"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 CommandBus_1 = require("../../../../core/command/CommandBus");
const LogErrorDecorator_1 = require("../../../../core/decorator/LogErrorDecorator");
const ValidatedArgs_1 = __importDefault(require("../../../../core/validation/ValidatedArgs"));
const GetInterestRateRequest_1 = __importDefault(require("../../../in/request/interestRates/GetInterestRateRequest"));
const SetInterestRateRequest_1 = __importDefault(require("../../../in/request/interestRates/SetInterestRateRequest"));
const GetImpactDataRequest_1 = __importDefault(require("../../../in/request/kpiLinkedRate/GetImpactDataRequest"));
const SetImpactDataRequest_1 = __importDefault(require("../../../in/request/interestRates/SetImpactDataRequest"));
const GetInterestRateQuery_1 = require("../../../../app/usecase/query/interestRates/getInterestRate/GetInterestRateQuery");
const GetImpactDataQuery_1 = require("../../../../app/usecase/query/interestRates/getImpactData/GetImpactDataQuery");
const SetInterestRateCommand_1 = require("../../../../app/usecase/command/interestRates/setInterestRate/SetInterestRateCommand");
const SetImpactDataCommand_1 = require("../../../../app/usecase/command/interestRates/setImpactData/SetImpactDataCommand");
class KpiLinkedRateInPort {
    queryBus;
    commandBus;
    constructor(queryBus = Injectable_1.default.resolve(QueryBus_1.QueryBus), commandBus = Injectable_1.default.resolve(CommandBus_1.CommandBus)) {
        this.queryBus = queryBus;
        this.commandBus = commandBus;
    }
    async getInterestRate(request) {
        ValidatedArgs_1.default.handleValidation("GetInterestRateRequest", request);
        const query = new GetInterestRateQuery_1.GetInterestRateQuery(request.securityId);
        const result = await this.queryBus.execute(query);
        return {
            maxRate: result.maxRate,
            baseRate: result.baseRate,
            minRate: result.minRate,
            startPeriod: result.startPeriod,
            startRate: result.startRate,
            missedPenalty: result.missedPenalty,
            reportPeriod: result.reportPeriod,
            rateDecimals: result.rateDecimals,
        };
    }
    async getImpactData(request) {
        ValidatedArgs_1.default.handleValidation("GetImpactDataRequest", request);
        const query = new GetImpactDataQuery_1.GetImpactDataQuery(request.securityId);
        const result = await this.queryBus.execute(query);
        return {
            maxDeviationCap: result.maxDeviationCap,
            baseLine: result.baseLine,
            maxDeviationFloor: result.maxDeviationFloor,
            impactDataDecimals: result.impactDataDecimals,
            adjustmentPrecision: result.adjustmentPrecision,
        };
    }
    async setInterestRate(request) {
        ValidatedArgs_1.default.handleValidation("SetInterestRateRequest", request);
        const command = new SetInterestRateCommand_1.SetInterestRateCommand(request.securityId, request.maxRate, request.baseRate, request.minRate, request.startPeriod, request.startRate, request.missedPenalty, request.reportPeriod, request.rateDecimals);
        const result = await this.commandBus.execute(command);
        return {
            payload: result.payload,
            transactionId: result.transactionId,
        };
    }
    async setImpactData(request) {
        ValidatedArgs_1.default.handleValidation("SetImpactDataRequest", request);
        const command = new SetImpactDataCommand_1.SetImpactDataCommand(request.securityId, request.maxDeviationCap, request.baseLine, request.maxDeviationFloor, request.impactDataDecimals, request.adjustmentPrecision);
        const result = await this.commandBus.execute(command);
        return {
            payload: result.payload,
            transactionId: result.transactionId,
        };
    }
}
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetInterestRateRequest_1.default]),
    __metadata("design:returntype", Promise)
], KpiLinkedRateInPort.prototype, "getInterestRate", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetImpactDataRequest_1.default]),
    __metadata("design:returntype", Promise)
], KpiLinkedRateInPort.prototype, "getImpactData", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [SetInterestRateRequest_1.default]),
    __metadata("design:returntype", Promise)
], KpiLinkedRateInPort.prototype, "setInterestRate", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [SetImpactDataRequest_1.default]),
    __metadata("design:returntype", Promise)
], KpiLinkedRateInPort.prototype, "setImpactData", null);
const KpiLinkedRate = new KpiLinkedRateInPort();
exports.default = KpiLinkedRate;
