"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 });
/* eslint-disable @typescript-eslint/no-unused-vars */
const LogErrorDecorator_1 = require("../../../core/decorator/LogErrorDecorator");
const ValidatedArgs_1 = __importDefault(require("../../../core/validation/ValidatedArgs"));
const QueryBus_1 = require("../../../core/query/QueryBus");
const Injectable_1 = __importDefault(require("../../../core/injectable/Injectable"));
const CommandBus_1 = require("../../../core/command/CommandBus");
const GrantKycRequest_1 = __importDefault(require("../request/security/kyc/GrantKycRequest"));
const RevokeKycRequest_1 = __importDefault(require("../request/security/kyc/RevokeKycRequest"));
const GetKycAccountsCountRequest_1 = __importDefault(require("../request/security/kyc/GetKycAccountsCountRequest"));
const GetKycForRequest_1 = __importDefault(require("../request/security/kyc/GetKycForRequest"));
const GrantKycCommand_1 = require("../../../app/usecase/command/security/kyc/grantKyc/GrantKycCommand");
const RevokeKycCommand_1 = require("../../../app/usecase/command/security/kyc/revokeKyc/RevokeKycCommand");
const GetKycForQuery_1 = require("../../../app/usecase/query/security/kyc/getKycFor/GetKycForQuery");
const GetKycAccountsCountQuery_1 = require("../../../app/usecase/query/security/kyc/getKycAccountsCount/GetKycAccountsCountQuery");
const GetKycAccountsDataQuery_1 = require("../../../app/usecase/query/security/kyc/getKycAccountsData/GetKycAccountsDataQuery");
const GetKycAccountsDataRequest_1 = __importDefault(require("../request/security/kyc/GetKycAccountsDataRequest"));
const GetKycStatusForRequest_1 = __importDefault(require("../request/security/kyc/GetKycStatusForRequest"));
const GetKycStatusForQuery_1 = require("../../../app/usecase/query/security/kyc/getKycStatusFor/GetKycStatusForQuery");
const index_1 = require("../request/index");
const ActivateInternalKycCommand_1 = require("../../../app/usecase/command/security/kyc/activateInternalKyc/ActivateInternalKycCommand");
const DeactivateInternalKycCommand_1 = require("../../../app/usecase/command/security/kyc/deactivateInternalKyc/DeactivateInternalKycCommand");
const IsInternalKycActivatedQuery_1 = require("../../../app/usecase/query/security/kyc/isInternalKycActivated/IsInternalKycActivatedQuery");
class KycInPort {
    commandBus;
    queryBus;
    constructor(commandBus = Injectable_1.default.resolve(CommandBus_1.CommandBus), queryBus = Injectable_1.default.resolve(QueryBus_1.QueryBus)) {
        this.commandBus = commandBus;
        this.queryBus = queryBus;
    }
    async grantKyc(request) {
        ValidatedArgs_1.default.handleValidation("GrantKycRequest", request);
        return await this.commandBus.execute(new GrantKycCommand_1.GrantKycCommand(request.securityId, request.targetId, request.vcBase64));
    }
    async revokeKyc(request) {
        ValidatedArgs_1.default.handleValidation("RevokeKycRequest", request);
        return await this.commandBus.execute(new RevokeKycCommand_1.RevokeKycCommand(request.securityId, request.targetId));
    }
    async getKycFor(request) {
        ValidatedArgs_1.default.handleValidation("GetKycForRequest", request);
        const res = (await this.queryBus.execute(new GetKycForQuery_1.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) {
        ValidatedArgs_1.default.handleValidation("GetKycAccountsCountRequest", request);
        const res = (await this.queryBus.execute(new GetKycAccountsCountQuery_1.GetKycAccountsCountQuery(request.securityId, request.kycStatus)))
            .payload;
        return res;
    }
    async getKycAccountsData(request) {
        ValidatedArgs_1.default.handleValidation("GetKycAccountsData", request);
        const res = (await this.queryBus.execute(new GetKycAccountsDataQuery_1.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) {
        ValidatedArgs_1.default.handleValidation("GetKycStatusForRequest", request);
        const res = (await this.queryBus.execute(new GetKycStatusForQuery_1.GetKycStatusForQuery(request.securityId, request.targetId))).payload;
        return res;
    }
    async activateInternalKyc(request) {
        ValidatedArgs_1.default.handleValidation("ActivateInternalKycRequest", request);
        return await this.commandBus.execute(new ActivateInternalKycCommand_1.ActivateInternalKycCommand(request.securityId));
    }
    async deactivateInternalKyc(request) {
        ValidatedArgs_1.default.handleValidation("DeactivateInternalKycRequest", request);
        return await this.commandBus.execute(new DeactivateInternalKycCommand_1.DeactivateInternalKycCommand(request.securityId));
    }
    async isInternalKycActivated(request) {
        ValidatedArgs_1.default.handleValidation("IsInternalKycActivatedRequest", request);
        return (await this.queryBus.execute(new IsInternalKycActivatedQuery_1.IsInternalKycActivatedQuery(request.securityId))).payload;
    }
}
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GrantKycRequest_1.default]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "grantKyc", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [RevokeKycRequest_1.default]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "revokeKyc", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetKycForRequest_1.default]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "getKycFor", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetKycAccountsCountRequest_1.default]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "getKycAccountsCount", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetKycAccountsDataRequest_1.default]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "getKycAccountsData", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [GetKycStatusForRequest_1.default]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "getKycStatusFor", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [index_1.ActivateInternalKycRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "activateInternalKyc", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [index_1.DeactivateInternalKycRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "deactivateInternalKyc", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [index_1.IsInternalKycActivatedRequest]),
    __metadata("design:returntype", Promise)
], KycInPort.prototype, "isInternalKycActivated", null);
const Kyc = new KycInPort();
exports.default = Kyc;
