// 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);
};
/* eslint-disable @typescript-eslint/no-unused-vars */
import { LogError } from "../../../core/decorator/LogErrorDecorator";
import ValidatedRequest from "../../../core/validation/ValidatedArgs";
import { QueryBus } from "../../../core/query/QueryBus";
import Injectable from "../../../core/injectable/Injectable";
import { CommandBus } from "../../../core/command/CommandBus";
import GrantKycRequest from "../request/security/kyc/GrantKycRequest";
import RevokeKycRequest from "../request/security/kyc/RevokeKycRequest";
import GetKycAccountsCountRequest from "../request/security/kyc/GetKycAccountsCountRequest";
import GetKycForRequest from "../request/security/kyc/GetKycForRequest";
import { GrantKycCommand } from "../../../app/usecase/command/security/kyc/grantKyc/GrantKycCommand";
import { RevokeKycCommand } from "../../../app/usecase/command/security/kyc/revokeKyc/RevokeKycCommand";
import { GetKycForQuery } from "../../../app/usecase/query/security/kyc/getKycFor/GetKycForQuery";
import { GetKycAccountsCountQuery } from "../../../app/usecase/query/security/kyc/getKycAccountsCount/GetKycAccountsCountQuery";
import { GetKycAccountsDataQuery } from "../../../app/usecase/query/security/kyc/getKycAccountsData/GetKycAccountsDataQuery";
import GetKycAccountsDataRequest from "../request/security/kyc/GetKycAccountsDataRequest";
import GetKycStatusForRequest from "../request/security/kyc/GetKycStatusForRequest";
import { GetKycStatusForQuery } from "../../../app/usecase/query/security/kyc/getKycStatusFor/GetKycStatusForQuery";
import { ActivateInternalKycRequest, DeactivateInternalKycRequest, IsInternalKycActivatedRequest, } from "../request/index";
import { ActivateInternalKycCommand } from "../../../app/usecase/command/security/kyc/activateInternalKyc/ActivateInternalKycCommand";
import { DeactivateInternalKycCommand } from "../../../app/usecase/command/security/kyc/deactivateInternalKyc/DeactivateInternalKycCommand";
import { IsInternalKycActivatedQuery } from "../../../app/usecase/query/security/kyc/isInternalKycActivated/IsInternalKycActivatedQuery";
class KycInPort {
    commandBus;
    queryBus;
    constructor(commandBus = Injectable.resolve(CommandBus), queryBus = Injectable.resolve(QueryBus)) {
        this.commandBus = commandBus;
        this.queryBus = queryBus;
    }
    async grantKyc(request) {
        ValidatedRequest.handleValidation("GrantKycRequest", request);
        return await this.commandBus.execute(new GrantKycCommand(request.securityId, request.targetId, request.vcBase64));
    }
    async revokeKyc(request) {
        ValidatedRequest.handleValidation("RevokeKycRequest", request);
        return await this.commandBus.execute(new RevokeKycCommand(request.securityId, request.targetId));
    }
    async getKycFor(request) {
        ValidatedRequest.handleValidation("GetKycForRequest", request);
        const res = (await this.queryBus.execute(new GetKycForQuery(request.securityId, request.targetId))).payload;
        const kyc = {
            validFrom: res.validFrom,
            validTo: res.validTo,
            vcId: res.vcId,
            issuer: res.issuer,
            status: res.status,
        };
        return kyc;
    }
    async getKycAccountsCount(request) {
        ValidatedRequest.handleValidation("GetKycAccountsCountRequest", request);
        const res = (await this.queryBus.execute(new GetKycAccountsCountQuery(request.securityId, request.kycStatus)))
            .payload;
        return res;
    }
    async getKycAccountsData(request) {
        ValidatedRequest.handleValidation("GetKycAccountsData", request);
        const res = (await this.queryBus.execute(new GetKycAccountsDataQuery(request.securityId, request.kycStatus, request.start, request.end))).payload;
        const kycData = res.map((item) => ({
            account: item.account,
            validFrom: item.validFrom,
            validTo: item.validTo,
            vcId: item.vcId,
            issuer: item.issuer,
            status: item.status,
        }));
        return kycData;
    }
    async getKycStatusFor(request) {
        ValidatedRequest.handleValidation("GetKycStatusForRequest", request);
        const res = (await this.queryBus.execute(new GetKycStatusForQuery(request.securityId, request.targetId))).payload;
        return res;
    }
    async activateInternalKyc(request) {
        ValidatedRequest.handleValidation("ActivateInternalKycRequest", request);
        return await this.commandBus.execute(new ActivateInternalKycCommand(request.securityId));
    }
    async deactivateInternalKyc(request) {
        ValidatedRequest.handleValidation("DeactivateInternalKycRequest", request);
        return await this.commandBus.execute(new DeactivateInternalKycCommand(request.securityId));
    }
    async isInternalKycActivated(request) {
        ValidatedRequest.handleValidation("IsInternalKycActivatedRequest", request);
        return (await this.queryBus.execute(new IsInternalKycActivatedQuery(request.securityId))).payload;
    }
}
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GrantKycRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "grantKyc", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [RevokeKycRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "revokeKyc", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetKycForRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "getKycFor", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetKycAccountsCountRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "getKycAccountsCount", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetKycAccountsDataRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "getKycAccountsData", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetKycStatusForRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "getKycStatusFor", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [ActivateInternalKycRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "activateInternalKyc", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [DeactivateInternalKycRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "deactivateInternalKyc", null);
__decorate([
    LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [IsInternalKycActivatedRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "isInternalKycActivated", null);
const Kyc = new KycInPort();
export default Kyc;
