"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeparturesDirectionRepository = void 0;
const const_1 = require("../../../../../../schema-definitions/const");
const helpers_1 = require("@golemio/core/dist/integration-engine/helpers");
const models_1 = require("@golemio/core/dist/integration-engine/models");
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator");
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
const DeparturesDirectionDto_1 = require("../../../../../../schema-definitions/ropid-gtfs/models/DeparturesDirectionDto");
let DeparturesDirectionRepository = class DeparturesDirectionRepository extends models_1.PostgresModel {
    constructor() {
        super("DeparturesDirectionRepository", {
            pgTableName: DeparturesDirectionDto_1.DeparturesDirectionModel.TABLE_NAME,
            pgSchema: const_1.PG_SCHEMA,
            outputSequelizeAttributes: DeparturesDirectionDto_1.DeparturesDirectionModel.attributeModel,
            savingType: "insertOnly",
        }, new golemio_validator_1.JSONSchemaValidator("DeparturesDirectionRepository", DeparturesDirectionDto_1.DeparturesDirectionModel.arrayJsonSchema));
        this.saveData = async (data, shouldReplace = true, isReturning = false) => {
            let transaction;
            try {
                await this.validate(data);
                transaction = await this.sequelizeModel.sequelize?.transaction();
                if (shouldReplace) {
                    await this.sequelizeModel.destroy({ where: {}, transaction });
                }
                const instances = await this.sequelizeModel.bulkCreate(data, {
                    ignoreDuplicates: true,
                    returning: isReturning,
                    transaction,
                });
                await transaction?.commit();
                return instances;
            }
            catch (err) {
                const exception = new golemio_errors_1.GeneralError(`[${this.constructor.name}] Could not save data: ${err.message}`, this.constructor.name, err);
                helpers_1.log.error(exception);
                await transaction?.rollback();
                throw exception;
            }
        };
    }
};
exports.DeparturesDirectionRepository = DeparturesDirectionRepository;
exports.DeparturesDirectionRepository = DeparturesDirectionRepository = __decorate([
    (0, tsyringe_1.injectable)(),
    __metadata("design:paramtypes", [])
], DeparturesDirectionRepository);
//# sourceMappingURL=DeparturesDirectionRepository.js.map