'use strict';
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = readAuditLog;
const harperBridge = require('./harperBridge/harperBridge').default;
const hdbUtils = __importStar(require("../utility/common_utils.js"));
const hdbTerms = __importStar(require("../utility/hdbTerms.js"));
const envMgr = __importStar(require("../utility/environment/environmentManager.js"));
const hdbError_ts_1 = require("../utility/errors/hdbError.js");
const commonErrors_ts_1 = require("../utility/errors/commonErrors.js");
const SEARCH_TYPES = Object.values(hdbTerms.READ_AUDIT_LOG_SEARCH_TYPES_ENUM);
const LOG_NOT_ENABLED_ERR = 'To use this operation audit log must be enabled in harperdb-config.yaml';
/**
 *
 * @param {ReadAuditLogObject} readAuditLogObject
 * @returns {Promise<void>}
 */
async function readAuditLog(readAuditLogObject) {
    const database = readAuditLogObject.database || readAuditLogObject.schema;
    if (hdbUtils.isEmpty(database)) {
        throw new Error(commonErrors_ts_1.HDB_ERROR_MSGS.SCHEMA_REQUIRED_ERR);
    }
    if (hdbUtils.isEmpty(readAuditLogObject.table)) {
        throw new Error(commonErrors_ts_1.HDB_ERROR_MSGS.TABLE_REQUIRED_ERR);
    }
    if (!envMgr.get(hdbTerms.CONFIG_PARAMS.LOGGING_AUDITLOG)) {
        throw (0, hdbError_ts_1.handleHDBError)(new Error(), LOG_NOT_ENABLED_ERR, commonErrors_ts_1.HTTP_STATUS_CODES.BAD_REQUEST, hdbTerms.LOG_LEVELS.ERROR, LOG_NOT_ENABLED_ERR, true);
    }
    const invalidSchemaTableMsg = hdbUtils.checkSchemaTableExist(database, readAuditLogObject.table);
    if (invalidSchemaTableMsg) {
        throw (0, hdbError_ts_1.handleHDBError)(new Error(), invalidSchemaTableMsg, commonErrors_ts_1.HTTP_STATUS_CODES.NOT_FOUND, hdbTerms.LOG_LEVELS.ERROR, invalidSchemaTableMsg, true);
    }
    if (!hdbUtils.isEmpty(readAuditLogObject.search_type) && SEARCH_TYPES.indexOf(readAuditLogObject.search_type) < 0) {
        throw new Error(`Invalid searchType '${readAuditLogObject.search_type}'`);
    }
    return await harperBridge.readAuditLog(readAuditLogObject);
}
//# sourceMappingURL=readAuditLog.js.map