"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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 (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MongooseHelper = void 0;
const Models = __importStar(require("../models/models"));
const mongoose_deletes_1 = __importDefault(require("./mongoose-deletes"));
const mongoose_inserts_1 = __importDefault(require("./mongoose-inserts"));
const mongoose_queries_1 = __importDefault(require("./mongoose-queries"));
const mongoose_connection_1 = __importDefault(require("./mongoose-connection"));
class MongooseHelper {
    constructor(userProperties) {
        this.userProperties = userProperties;
        // mongoose.plugin( ( schema: mongoose.Schema ) => {
        //   schema.options.toJSON = {
        //     virtuals: true,
        //     versionKey: false,
        //     transform( doc, ret ) {
        //       ret.id = ret._id;
        //       delete ret._id;
        //     }
        //   };
        // } );
    }
    async insertReport(report) {
        const connection = await new mongoose_connection_1.default(this.userProperties).connect();
        const models = this.initalizeModels(connection);
        const objectId = await new mongoose_inserts_1.default(models).insertReport(report);
        await connection.close();
        return objectId;
    }
    async getReportById(id) {
        const connection = await new mongoose_connection_1.default(this.userProperties).connect();
        const models = this.initalizeModels(connection);
        const report = await new mongoose_queries_1.default(models).getReportById(id);
        await connection.close();
        return report;
    }
    async getAllTheElementsOrderedAndFiltered(orderValue, orderDirection, filterValue) {
        const connection = await new mongoose_connection_1.default(this.userProperties).connect();
        const models = this.initalizeModels(connection);
        const reports = await new mongoose_queries_1.default(models).getAllTheElementsOrderedAndFiltered(orderValue, orderDirection, filterValue);
        await connection.close();
        return reports;
    }
    async deleteReportById(id) {
        const connection = await new mongoose_connection_1.default(this.userProperties).connect();
        const models = this.initalizeModels(connection);
        await new mongoose_deletes_1.default(models).deleteReportById(id);
        await connection.close();
    }
    async getDatabaseSize() {
        const mongooseConnection = new mongoose_connection_1.default(this.userProperties);
        const connection = await mongooseConnection.connect();
        const databaseSize = await mongooseConnection.getDatabaseSize();
        await connection.close();
        return databaseSize;
    }
    initalizeModels(mongooseConnection) {
        return {
            featureModel: mongooseConnection.model('Feature', Models.featureSchema, this.userProperties.mongoDb?.collections.features),
            reportModel: mongooseConnection.model('ExtendedReport', Models.reportsSchema, this.userProperties.mongoDb?.collections.reports),
            scenarioModel: mongooseConnection.model('Scenario', Models.scenarioSchema, this.userProperties.mongoDb?.collections.scenarios),
            stepModel: mongooseConnection.model('Step', Models.stepSchema, this.userProperties.mongoDb?.collections.steps),
        };
    }
}
exports.MongooseHelper = MongooseHelper;
//# sourceMappingURL=mongoose-helper.js.map