// 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);
};
import Injectable from "../../../../core/injectable/Injectable";
import { QueryBus } from "../../../../core/query/QueryBus";
import { CommandBus } from "../../../../core/command/CommandBus";
import { LogError } from "../../../../core/decorator/LogErrorDecorator";
import ValidatedRequest from "../../../../core/validation/ValidatedArgs";
import GetInterestRateRequest from "../../../in/request/interestRates/GetInterestRateRequest";
import SetInterestRateRequest from "../../../in/request/interestRates/SetInterestRateRequest";
import GetImpactDataRequest from "../../../in/request/kpiLinkedRate/GetImpactDataRequest";
import SetImpactDataRequest from "../../../in/request/interestRates/SetImpactDataRequest";
import { GetInterestRateQuery, } from "../../../../app/usecase/query/interestRates/getInterestRate/GetInterestRateQuery";
import { GetImpactDataQuery, } from "../../../../app/usecase/query/interestRates/getImpactData/GetImpactDataQuery";
import { SetInterestRateCommand, } from "../../../../app/usecase/command/interestRates/setInterestRate/SetInterestRateCommand";
import { SetImpactDataCommand, } from "../../../../app/usecase/command/interestRates/setImpactData/SetImpactDataCommand";
class KpiLinkedRateInPort {
    queryBus;
    commandBus;
    constructor(queryBus = Injectable.resolve(QueryBus), commandBus = Injectable.resolve(CommandBus)) {
        this.queryBus = queryBus;
        this.commandBus = commandBus;
    }
    async getInterestRate(request) {
        ValidatedRequest.handleValidation("GetInterestRateRequest", request);
        const query = new 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) {
        ValidatedRequest.handleValidation("GetImpactDataRequest", request);
        const query = new 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) {
        ValidatedRequest.handleValidation("SetInterestRateRequest", request);
        const command = new 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) {
        ValidatedRequest.handleValidation("SetImpactDataRequest", request);
        const command = new 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([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetInterestRateRequest]),
    __metadata("design:returntype", Promise)
], KpiLinkedRateInPort.prototype, "getInterestRate", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetImpactDataRequest]),
    __metadata("design:returntype", Promise)
], KpiLinkedRateInPort.prototype, "getImpactData", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [SetInterestRateRequest]),
    __metadata("design:returntype", Promise)
], KpiLinkedRateInPort.prototype, "setInterestRate", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [SetImpactDataRequest]),
    __metadata("design:returntype", Promise)
], KpiLinkedRateInPort.prototype, "setImpactData", null);
const KpiLinkedRate = new KpiLinkedRateInPort();
export default KpiLinkedRate;
