"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.RopidGTFSStopsModel = void 0;
const StopEnums_1 = require("../../helpers/StopEnums");
const const_1 = require("../../schema-definitions/const");
const ropid_gtfs_1 = require("../../schema-definitions/ropid-gtfs");
const StopDto_1 = require("../../schema-definitions/ropid-gtfs/models/StopDto");
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");
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
let RopidGTFSStopsModel = class RopidGTFSStopsModel extends integration_engine_1.PostgresModel {
    constructor() {
        super(ropid_gtfs_1.RopidGTFS.stops.name + "Model", {
            outputSequelizeAttributes: ropid_gtfs_1.RopidGTFS.stops.outputSequelizeAttributes,
            pgTableName: ropid_gtfs_1.RopidGTFS.stops.pgTableName,
            pgSchema: const_1.PG_SCHEMA,
            savingType: "insertOnly",
        }, new golemio_validator_1.JSONSchemaValidator(ropid_gtfs_1.RopidGTFS.stops.name + "ModelValidator", StopDto_1.StopDto.jsonSchema));
        this.getAll = async () => {
            try {
                return this.sequelizeModel.findAll();
            }
            catch (err) {
                throw new golemio_errors_1.GeneralError("Database error", "RopidGTFSStopsModel", err, 500);
            }
        };
        /**
         *  Retrieve all stops data needed for cache where location_type is 0 and computed_cis_stop_id is not null
         */
        this.getStopsForCache = async () => {
            try {
                const stops = (await this.sequelizeModel.findAll({
                    attributes: [
                        "stop_id",
                        "asw_node_id",
                        "stop_name",
                        "platform_code",
                        "wheelchair_boarding",
                        "zone_id",
                        "computed_cis_stop_id",
                    ],
                    raw: true,
                    where: {
                        location_type: StopEnums_1.GtfsStopLocationType.StopOrPlatform,
                        computed_cis_stop_id: { [sequelize_1.Op.not]: null },
                    },
                }));
                if (!stops || stops.length === 0) {
                    return [];
                }
                return stops;
            }
            catch (error) {
                throw new golemio_errors_1.GeneralError("Error while getting GTFS stop ids", this.constructor.name, error);
            }
        };
    }
};
exports.RopidGTFSStopsModel = RopidGTFSStopsModel;
exports.RopidGTFSStopsModel = RopidGTFSStopsModel = __decorate([
    (0, tsyringe_1.injectable)(),
    __metadata("design:paramtypes", [])
], RopidGTFSStopsModel);
//# sourceMappingURL=RopidGTFSStopsModel.js.map