"use strict";
// SPDX-License-Identifier: Apache-2.0
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SecurityOperations = void 0;
const ethers_1 = require("ethers");
const asset_tokenization_contracts_1 = require("@hashgraph/asset-tokenization-contracts");
const Constants_1 = require("../../../../core/Constants");
const RateStatus_1 = require("../../../../domain/context/bond/RateStatus");
const LogService_1 = __importDefault(require("../../../../app/service/log/LogService"));
class SecurityOperations {
    executor;
    constructor(executor) {
        this.executor = executor;
    }
    async setCoupon(security, recordDate, executionDate, rate, startDate, endDate, fixingDate, rateStatus, securityId) {
        LogService_1.default.logTrace(`bond: ${security} , recordDate :${recordDate} , executionDate: ${executionDate}, rate : ${rate}, startDate: ${startDate}, endDate: ${endDate}, fixingDate: ${fixingDate}, rateStatus: ${rateStatus}`);
        const coupon = {
            recordDate: recordDate.toHexString(),
            executionDate: executionDate.toHexString(),
            rate: rate.toHexString(),
            rateDecimals: rate.decimals,
            startDate: startDate.toBigInt(),
            endDate: endDate.toBigInt(),
            fixingDate: fixingDate.toBigInt(),
            rateStatus: RateStatus_1.CastRateStatus.toNumber(rateStatus),
        };
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.BondUSAFacet__factory.createInterface(), "setCoupon", [coupon], Constants_1.GAS.SET_COUPON);
    }
    async cancelCoupon(security, couponId, securityId) {
        LogService_1.default.logTrace(`Cancelling coupon: ${couponId} for bond: ${security}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.BondUSAFacet__factory.createInterface(), "cancelCoupon", [couponId], Constants_1.GAS.CANCEL_COUPON);
    }
    setRate(security, rate, rateDecimals, securityId) {
        LogService_1.default.logTrace(`Setting Rate ${rate.toString()} with decimals ${rateDecimals} for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.FixedRate__factory.createInterface(), "setRate", [rate, rateDecimals], Constants_1.GAS.SET_RATE);
    }
    setInterestRate(security, maxRate, baseRate, minRate, startPeriod, startRate, missedPenalty, reportPeriod, rateDecimals, securityId) {
        LogService_1.default.logTrace(`Setting Interest Rate for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.KpiLinkedRate__factory.createInterface(), "setInterestRate", [
            {
                maxRate,
                baseRate,
                minRate,
                startPeriod,
                startRate,
                missedPenalty,
                reportPeriod,
                rateDecimals,
            },
        ], Constants_1.GAS.SET_INTEREST_RATE);
    }
    setImpactData(security, maxDeviationCap, baseLine, maxDeviationFloor, impactDataDecimals, adjustmentPrecision, securityId) {
        LogService_1.default.logTrace(`Setting Impact Data for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.KpiLinkedRate__factory.createInterface(), "setImpactData", [
            {
                maxDeviationCap,
                baseLine,
                maxDeviationFloor,
                impactDataDecimals,
                adjustmentPrecision,
            },
        ], Constants_1.GAS.SET_IMPACT_DATA);
    }
    addKpiData(security, date, value, project, securityId) {
        LogService_1.default.logTrace(`Adding KPI data for security ${security.toString()}, date: ${date}, value: ${value}, project: ${project.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers_1.ethers.Interface(asset_tokenization_contracts_1.Kpis__factory.abi), "addKpiData", [date, value, project.toString()], Constants_1.GAS.ADD_KPI_DATA);
    }
    async updateMaturityDate(security, maturityDate, securityId) {
        LogService_1.default.logTrace(`Updating bond maturity date ${maturityDate} for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers_1.ethers.Interface(asset_tokenization_contracts_1.Bond__factory.abi), "updateMaturityDate", [maturityDate], Constants_1.GAS.UPDATE_MATURITY_DATE);
    }
    addProceedRecipient(security, proceedRecipient, data, securityId) {
        LogService_1.default.logTrace(`Adding proceedRecipient: ${proceedRecipient} to security: ${security}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ProceedRecipientsFacet__factory.createInterface(), "addProceedRecipient", [proceedRecipient.toString(), data], Constants_1.GAS.ADD_PROCEED_RECIPIENT);
    }
    removeProceedRecipient(security, proceedRecipient, securityId) {
        LogService_1.default.logTrace(`Removing proceedRecipient: ${proceedRecipient} from security: ${security}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ProceedRecipientsFacet__factory.createInterface(), "removeProceedRecipient", [proceedRecipient.toString()], Constants_1.GAS.REMOVE_PROCEED_RECIPIENT);
    }
    updateProceedRecipientData(security, proceedRecipient, data, securityId) {
        LogService_1.default.logTrace(`Updating proceedRecipient: ${proceedRecipient} data in security: ${security}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ProceedRecipientsFacet__factory.createInterface(), "updateProceedRecipientData", [proceedRecipient.toString(), data], Constants_1.GAS.UPDATE_PROCEED_RECIPIENT);
    }
    async setDividend(security, recordDate, executionDate, amount, securityId) {
        LogService_1.default.logTrace(`equity: ${security} , recordDate :${recordDate} , executionDate: ${executionDate}, amount : ${amount}`);
        const dividend = {
            recordDate: recordDate.toHexString(),
            executionDate: executionDate.toHexString(),
            amount: amount.toHexString(),
            amountDecimals: amount.decimals,
        };
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.EquityUSAFacet__factory.createInterface(), "setDividend", [dividend], Constants_1.GAS.SET_DIVIDENDS);
    }
    async cancelDividend(security, dividendId, securityId) {
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.EquityUSAFacet__factory.createInterface(), "cancelDividend", [dividendId], Constants_1.GAS.CANCEL_DIVIDEND);
    }
    async setVotingRights(security, recordDate, data, securityId) {
        LogService_1.default.logTrace(`equity: ${security} , recordDate :${recordDate}`);
        const voting = {
            recordDate: recordDate.toHexString(),
            data: data,
        };
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.EquityUSAFacet__factory.createInterface(), "setVoting", [voting], Constants_1.GAS.SET_VOTING_RIGHTS);
    }
    async cancelVoting(security, votingId, securityId) {
        LogService_1.default.logTrace(`Cancelling voting: ${votingId} for equity: ${security}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.EquityUSAFacet__factory.createInterface(), "cancelVoting", [votingId], Constants_1.GAS.CANCEL_VOTING);
    }
    async setScheduledBalanceAdjustment(security, executionDate, factor, decimals, securityId) {
        LogService_1.default.logTrace(`equity: ${security} , executionDate :${executionDate} , factor: ${factor}, decimals : ${decimals}`);
        const scheduleBalanceAdjustment = {
            executionDate: executionDate.toHexString(),
            factor: factor.toHexString(),
            decimals: decimals.toHexString(),
        };
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.EquityUSAFacet__factory.createInterface(), "setScheduledBalanceAdjustment", [scheduleBalanceAdjustment], Constants_1.GAS.SET_SCHEDULED_BALANCE_ADJUSTMENT);
    }
    async cancelScheduledBalanceAdjustment(security, balanceAdjustmentId, securityId) {
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.EquityUSAFacet__factory.createInterface(), "cancelScheduledBalanceAdjustment", [balanceAdjustmentId], Constants_1.GAS.CANCEL_SCHEDULED_BALANCE_ADJUSTMENT);
    }
    async takeSnapshot(security, securityId) {
        LogService_1.default.logTrace(`Take snapshot of: ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.SnapshotsFacet__factory.createInterface(), "takeSnapshot", [], Constants_1.GAS.TAKE_SNAPSHOT);
    }
    async triggerPendingScheduledSnapshots(security, securityId) {
        LogService_1.default.logTrace(`Triggering pending scheduled snapshots for ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ScheduledCrossOrderedTasksFacet__factory.createInterface(), "triggerPendingScheduledCrossOrderedTasks", [], Constants_1.GAS.TRIGGER_PENDING_SCHEDULED_SNAPSHOTS);
    }
    async triggerScheduledSnapshots(security, max, securityId) {
        LogService_1.default.logTrace(`Triggering up to ${max.toString()} pending scheduled snapshots for ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ScheduledCrossOrderedTasksFacet__factory.createInterface(), "triggerScheduledCrossOrderedTasks", [max.toHexString()], Constants_1.GAS.TRIGGER_PENDING_SCHEDULED_SNAPSHOTS);
    }
}
exports.SecurityOperations = SecurityOperations;
