"use strict";
// SPDX-License-Identifier: Apache-2.0
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 __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Injectable_1 = __importDefault(require("../../../core/injectable/Injectable"));
const QueryBus_1 = require("../../../core/query/QueryBus");
const LogErrorDecorator_1 = require("../../../core/decorator/LogErrorDecorator");
const ValidatedArgs_1 = __importDefault(require("../../../core/validation/ValidatedArgs"));
const GetLatestKpiDataQuery_1 = require("../../../app/usecase/query/interestRates/getLatestKpiData/GetLatestKpiDataQuery");
const GetLatestKpiDataRequest_1 = __importDefault(require("../request/kpis/GetLatestKpiDataRequest"));
const GetMinDateQuery_1 = require("../../../app/usecase/query/kpis/getMinDate/GetMinDateQuery");
const GetMinDateRequest_1 = __importDefault(require("../request/kpis/GetMinDateRequest"));
const IsCheckPointDateQuery_1 = require("../../../app/usecase/query/kpis/isCheckPointDate/IsCheckPointDateQuery");
const IsCheckPointDateRequest_1 = __importDefault(require("../request/kpis/IsCheckPointDateRequest"));
class KpisInPort {
    queryBus;
    constructor(queryBus = Injectable_1.default.resolve(QueryBus_1.QueryBus)) {
        this.queryBus = queryBus;
    }
    async getLatestKpiData(request) {
        ValidatedArgs_1.default.handleValidation("GetLatestKpiDataRequest", request);
        const response = await this.queryBus.execute(new GetLatestKpiDataQuery_1.GetLatestKpiDataQuery(request.securityId, BigInt(request.from), BigInt(request.to), request.kpi));
        return { value: response.value, exists: response.exists };
    }
    async getMinDate(request) {
        ValidatedArgs_1.default.handleValidation("GetMinDateRequest", request);
        const result = await this.queryBus.execute(new GetMinDateQuery_1.GetMinDateQuery(request.securityId));
        return result.minDate;
    }
    async isCheckPointDate(request) {
        ValidatedArgs_1.default.handleValidation("IsCheckPointDateRequest", request);
        const result = await this.queryBus.execute(new IsCheckPointDateQuery_1.IsCheckPointDateQuery(request.securityId, BigInt(request.date), request.project));
        return result.isCheckPoint;
    }
}
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetLatestKpiDataRequest_1.default]),
    __metadata("design:returntype", Promise)
], KpisInPort.prototype, "getLatestKpiData", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetMinDateRequest_1.default]),
    __metadata("design:returntype", Promise)
], KpisInPort.prototype, "getMinDate", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [IsCheckPointDateRequest_1.default]),
    __metadata("design:returntype", Promise)
], KpisInPort.prototype, "isCheckPointDate", null);
const Kpis = new KpisInPort();
exports.default = Kpis;
