"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);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.V1EventsController = void 0;
const OgJisToken_1 = require("../../ioc/OgJisToken");
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
const JISEventsRepository_1 = require("../../data-access/JISEventsRepository");
const JISEventsCustomFormatTransformation_1 = require("../../transformations/JISEventsCustomFormatTransformation");
const monitoring_1 = require("@golemio/core/dist/monitoring");
const EventsDto_1 = require("../../dto/EventsDto");
const shared_1 = require("../../../shared");
const express_validator_1 = require("@golemio/core/dist/shared/express-validator");
let V1EventsController = class V1EventsController {
    constructor(jisEventsRepository, eventsCustomFormatTransformation) {
        this.jisEventsRepository = jisEventsRepository;
        this.eventsCustomFormatTransformation = eventsCustomFormatTransformation;
        this.getAllEventsInCustomFormat = async (req, res, next) => {
            const span = (0, monitoring_1.createChildSpan)("V1EventsController.getAllEventsInCustomFormat");
            const queryData = (0, express_validator_1.matchedData)(req);
            try {
                const { displayPeriodEnd, displayPeriodStart, organizationNames, type } = shared_1.RopidRouterUtils.mapObjectToDTOInstance(EventsDto_1.EventsCustomFormatQueryDto, queryData);
                const events = await this.jisEventsRepository.getAllForCustomFormat(organizationNames, displayPeriodStart, displayPeriodEnd, type);
                const transformedEvents = this.eventsCustomFormatTransformation.transformArray(events);
                return res.status(200).json(transformedEvents);
            }
            catch (err) {
                span?.recordException(err);
                next(err);
            }
            finally {
                span?.end();
            }
        };
    }
};
exports.V1EventsController = V1EventsController;
exports.V1EventsController = V1EventsController = __decorate([
    (0, tsyringe_1.injectable)(),
    __param(0, (0, tsyringe_1.inject)(OgJisToken_1.OgJisToken.JISEventsRepository)),
    __param(1, (0, tsyringe_1.inject)(OgJisToken_1.OgJisToken.JISEventsCustomFormatTransformation)),
    __metadata("design:paramtypes", [JISEventsRepository_1.JISEventsRepository,
        JISEventsCustomFormatTransformation_1.JISEventsCustomFormatTransformation])
], V1EventsController);
//# sourceMappingURL=V1EventsController.js.map