'use strict';

function whereOr(query, table, builder) {
    if (!query) {
        return {};
    }

    Object.entries(query).forEach(([key, value]) => {
        if (value === undefined) {
            return builder;
        }

        if (Array.isArray(value)) {
            builder.orWhereIn(`${table}.${key}`, value);
            return builder;
        }

        builder.orWhere(`${table}.${key}`, value);
        return builder;
    });

    return builder;
}

module.exports = whereOr;
