'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.searchByConditions = searchByConditions;
exports.searchByHash = searchByHash;
exports.searchByValue = searchByValue;
exports.search = search;
const harperBridge = require('./harperBridge/harperBridge').default;
const common_utils_ts_1 = require("../utility/common_utils.js");
async function searchByConditions(searchObject) {
    (0, common_utils_ts_1.transformReq)(searchObject);
    return harperBridge.searchByConditions(searchObject);
}
async function searchByHash(searchObject) {
    (0, common_utils_ts_1.transformReq)(searchObject);
    if (searchObject.ids)
        searchObject.hash_values = searchObject.ids;
    let array = [];
    for await (let record of harperBridge.searchByHash(searchObject)) {
        if (record)
            array.push(record);
    }
    return array;
}
async function searchByValue(searchObject) {
    (0, common_utils_ts_1.transformReq)(searchObject);
    if (searchObject.hasOwnProperty('desc') === true) {
        searchObject.reverse = searchObject.desc;
    }
    const array = [];
    for await (let record of harperBridge.searchByValue(searchObject)) {
        array.push(record);
    }
    return array;
}
function search(statement, callback) {
    try {
        const SelectValidator = require('../sqlTranslator/SelectValidator').default || require('../sqlTranslator/SelectValidator');
        const SQLSearch = require('./SQLSearch').default || require('./SQLSearch');
        let validator = new SelectValidator(statement);
        validator.validate();
        let sqlSearch = new SQLSearch(validator.statement, validator.attributes);
        sqlSearch
            .search()
            .then((data) => {
            callback(null, data);
        })
            .catch((e) => {
            callback(e, null);
        });
    }
    catch (e) {
        return callback(e);
    }
}
//# sourceMappingURL=search.js.map