"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TripsHistoryRepository = void 0;
const const_1 = require("../../../../../schema-definitions/const");
const models_1 = require("../../../../../schema-definitions/vehicle-positions/models");
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 TripsHistoryRepository extends integration_engine_1.PostgresModel {
    constructor() {
        super("VPTripsHistoryRepository", {
            pgTableName: models_1.VPTripsModel.TABLE_NAME_HISTORY,
            pgSchema: const_1.PG_SCHEMA,
            outputSequelizeAttributes: models_1.VPTripsModel.attributeModel,
            savingType: "insertOrUpdate",
        }, new golemio_validator_1.JSONSchemaValidator("VPTripsHistoryRepositoryValidator", models_1.VPTripsModel.jsonSchema));
        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.TripsHistoryRepository = TripsHistoryRepository;
//# sourceMappingURL=TripsHistoryRepository.js.map