"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 });
exports.SecurityInPortInfo = void 0;
const LogErrorDecorator_1 = require("../../../../core/decorator/LogErrorDecorator");
const request_1 = require("../../request");
const ValidatedArgs_1 = __importDefault(require("../../../../core/validation/ValidatedArgs"));
const GetSecurityQuery_1 = require("../../../../app/usecase/query/security/get/GetSecurityQuery");
const BaseSecurityInPort_1 = require("../BaseSecurityInPort");
const GetSecurityHoldersQuery_1 = require("../../../../app/usecase/query/security/security/getSecurityHolders/GetSecurityHoldersQuery");
const GetTotalSecurityHoldersQuery_1 = require("../../../../app/usecase/query/security/security/getTotalSecurityHolders/GetTotalSecurityHoldersQuery");
class SecurityInPortInfo extends BaseSecurityInPort_1.BaseSecurityInPort {
    async getInfo(request) {
        const { securityId } = request;
        ValidatedArgs_1.default.handleValidation("GetSecurityDetailsRequest", request);
        const res = await this.queryBus.execute(new GetSecurityQuery_1.GetSecurityQuery(securityId));
        const security = {
            name: res.security.name,
            symbol: res.security.symbol,
            isin: res.security.isin,
            type: res.security.type,
            decimals: res.security.decimals,
            isWhiteList: res.security.isWhiteList,
            isControllable: res.security.isControllable,
            isMultiPartition: res.security.isMultiPartition,
            totalSupply: res.security.totalSupply?.toString(),
            maxSupply: res.security.maxSupply?.toString(),
            diamondAddress: res.security.diamondAddress?.toString(),
            evmDiamondAddress: res.security.evmDiamondAddress?.toString(),
            paused: res.security.paused,
            regulation: res.security.regulation,
            isCountryControlListWhiteList: res.security.isCountryControlListWhiteList,
            countries: res.security.countries,
            info: res.security.info,
        };
        return security;
    }
    async getSecurityHolders(request) {
        const { securityId, start, end } = request;
        ValidatedArgs_1.default.handleValidation(request_1.GetSecurityHoldersRequest.name, request);
        return (await this.queryBus.execute(new GetSecurityHoldersQuery_1.GetSecurityHoldersQuery(securityId, start, end))).payload;
    }
    async getTotalSecurityHolders(request) {
        const { securityId } = request;
        ValidatedArgs_1.default.handleValidation(request_1.GetTotalSecurityHoldersRequest.name, request);
        return (await this.queryBus.execute(new GetTotalSecurityHoldersQuery_1.GetTotalSecurityHoldersQuery(securityId))).payload;
    }
}
exports.SecurityInPortInfo = SecurityInPortInfo;
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetSecurityDetailsRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortInfo.prototype, "getInfo", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetSecurityHoldersRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortInfo.prototype, "getSecurityHolders", null);
__decorate([
    LogErrorDecorator_1.LogError,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [request_1.GetTotalSecurityHoldersRequest]),
    __metadata("design:returntype", Promise)
], SecurityInPortInfo.prototype, "getTotalSecurityHolders", null);
