"use strict";
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.SecurityDataBuilder = void 0;
const ImpactData_1 = require("../bond/ImpactData");
const InterestRate_1 = require("../bond/InterestRate");
const DividendType_1 = require("../equity/DividendType");
const BondDetailsData_1 = require("../factory/BondDetailsData");
const BondFixedRateDetailsData_1 = require("../factory/BondFixedRateDetailsData");
const BondKpiLinkedRateDetailsData_1 = require("../factory/BondKpiLinkedRateDetailsData");
const FactorySecurityToken_1 = require("../factory/FactorySecurityToken");
const RegulationType_1 = require("../factory/RegulationType");
const SecurityRole_1 = require("../security/SecurityRole");
class SecurityDataBuilder {
    static buildSecurityData(securityInfo, resolver, configId, configVersion, externalPauses = [], externalControlLists = [], externalKycLists = [], diamondOwnerAccount, compliance, identityRegistry) {
        const rbacAdmin = {
            role: SecurityRole_1.SecurityRole._DEFAULT_ADMIN_ROLE,
            members: [diamondOwnerAccount.toString()],
        };
        return {
            arePartitionsProtected: securityInfo.arePartitionsProtected,
            isMultiPartition: securityInfo.isMultiPartition,
            resolver: resolver.toString(),
            resolverProxyConfiguration: { key: configId, version: configVersion },
            rbacs: [rbacAdmin],
            isControllable: securityInfo.isControllable,
            isWhiteList: securityInfo.isWhiteList,
            erc20VotesActivated: securityInfo.erc20VotesActivated,
            maxSupply: securityInfo.maxSupply?.toString() || "0",
            erc20MetadataInfo: {
                name: securityInfo.name,
                symbol: securityInfo.symbol,
                isin: securityInfo.isin,
                decimals: securityInfo.decimals,
            },
            clearingActive: securityInfo.clearingActive,
            internalKycActivated: securityInfo.internalKycActivated,
            externalPauses: externalPauses.map((addr) => addr.toString()),
            externalControlLists: externalControlLists.map((addr) => addr.toString()),
            externalKycLists: externalKycLists.map((addr) => addr.toString()),
            compliance: compliance.toString(),
            identityRegistry: identityRegistry.toString(),
        };
    }
    static buildRegulationData(securityInfo) {
        return new FactorySecurityToken_1.FactoryRegulationData(RegulationType_1.CastRegulationType.toNumber(securityInfo.regulationType), RegulationType_1.CastRegulationSubType.toNumber(securityInfo.regulationsubType), {
            countriesControlListType: securityInfo.isCountryControlListWhiteList,
            listOfCountries: securityInfo.countries ?? "",
            info: securityInfo.info ?? "",
        });
    }
    static buildEquityDetails(equityInfo) {
        return {
            votingRight: equityInfo.votingRight,
            informationRight: equityInfo.informationRight,
            liquidationRight: equityInfo.liquidationRight,
            subscriptionRight: equityInfo.subscriptionRight,
            conversionRight: equityInfo.conversionRight,
            redemptionRight: equityInfo.redemptionRight,
            putRight: equityInfo.putRight,
            dividendRight: DividendType_1.CastDividendType.toNumber(equityInfo.dividendRight),
            currency: equityInfo.currency,
            nominalValue: equityInfo.nominalValue.toString(),
            nominalValueDecimals: equityInfo.nominalValueDecimals,
        };
    }
    static buildBondDetails(bondInfo) {
        return new BondDetailsData_1.BondDetailsData(bondInfo.currency, bondInfo.nominalValue.toString(), bondInfo.nominalValueDecimals, bondInfo.startingDate.toString(), bondInfo.maturityDate.toString());
    }
    static buildBondFixedRateDetails(bondInfo) {
        return new BondFixedRateDetailsData_1.BondFixedRateDetailsData(bondInfo.currency, bondInfo.nominalValue.toString(), bondInfo.nominalValueDecimals, bondInfo.startingDate.toString(), bondInfo.maturityDate.toString(), bondInfo.rate, bondInfo.rateDecimals);
    }
    static buildBondKpiLinkedRateDetails(bondInfo) {
        return new BondKpiLinkedRateDetailsData_1.BondKpiLinkedRateDetailsData(bondInfo.currency, bondInfo.nominalValue.toString(), bondInfo.nominalValueDecimals, bondInfo.startingDate.toString(), bondInfo.maturityDate.toString(), this.buildInterestRateData(bondInfo.interestRate), this.buildImpactData(bondInfo.impactData));
    }
    static buildInterestRateData(interestRate) {
        return new InterestRate_1.InterestRate(interestRate.maxRate, interestRate.baseRate, interestRate.minRate, interestRate.startPeriod, interestRate.startRate, interestRate.missedPenalty, interestRate.reportPeriod, interestRate.rateDecimals);
    }
    static buildImpactData(impactData) {
        return new ImpactData_1.ImpactData(impactData.maxDeviationCap, impactData.baseLine, impactData.maxDeviationFloor, impactData.impactDataDecimals, impactData.adjustmentPrecision);
    }
}
exports.SecurityDataBuilder = SecurityDataBuilder;
