"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CisStopRepository = void 0;
const const_1 = require("../../../../../schema-definitions/const");
const CisStopModel_1 = require("../../../../../schema-definitions/vehicle-positions/models/CisStopModel");
const integration_engine_1 = require("@golemio/core/dist/integration-engine");
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator");
const sequelize_1 = require("@golemio/core/dist/shared/sequelize");
class CisStopRepository extends integration_engine_1.PostgresModel {
    constructor() {
        super("VPCisStopRepository", {
            pgTableName: CisStopModel_1.CisStopModel.tableName,
            pgSchema: const_1.PG_SCHEMA,
            outputSequelizeAttributes: CisStopModel_1.CisStopModel.attributeModel,
            savingType: "insertOrUpdate",
        }, new golemio_validator_1.JSONSchemaValidator("VPCisStopRepositoryValidator", CisStopModel_1.CisStopModel.arrayJsonSchema));
        this.deleteNHoursOldData = async (hours) => {
            try {
                return await this.sequelizeModel.destroy({
                    where: {
                        updated_at: {
                            [sequelize_1.Op.lt]: sequelize_1.Sequelize.literal(`NOW() - INTERVAL '${hours} HOURS'`),
                        },
                    },
                });
            }
            catch (err) {
                throw new golemio_errors_1.GeneralError("Error while purging old data", this.constructor.name, err);
            }
        };
    }
}
exports.CisStopRepository = CisStopRepository;
//# sourceMappingURL=CisStopRepository.js.map