// SPDX-License-Identifier: Apache-2.0
import { ethers } from "ethers";
import { ERC1410IssuerFacet__factory, ERC3643OperationsFacet__factory, ERC3643BatchFacet__factory, Bond__factory, } from "@hashgraph/asset-tokenization-contracts";
import { _PARTITION_ID_1, GAS } from "../../../../core/Constants";
import LogService from "../../../../app/service/log/LogService";
export class IssuanceOperations {
    executor;
    constructor(executor) {
        this.executor = executor;
    }
    async issue(security, targetId, amount, securityId) {
        LogService.logTrace(`Issue ${amount} ${security} to account: ${targetId.toString()}`);
        const issueData = {
            partition: _PARTITION_ID_1,
            tokenHolder: targetId.toString(),
            value: amount.toHexString(),
            data: "0x",
        };
        return this.executor.executeContractCall(securityId.toString(), ERC1410IssuerFacet__factory.createInterface(), "issueByPartition", [issueData], GAS.ISSUE);
    }
    async mint(security, target, amount, securityId) {
        LogService.logTrace(`Minting ${amount} ${security} to account: ${target.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), ERC3643OperationsFacet__factory.createInterface(), "mint", [target.toString(), amount.toHexString()], GAS.MINT);
    }
    async batchMint(security, amountList, toList, securityId) {
        LogService.logTrace(`Batch minting ${amountList.length} tokens to ${toList.map((item) => item.toString())}`);
        return this.executor.executeContractCall(securityId.toString(), ERC3643BatchFacet__factory.createInterface(), "batchMint", [toList.map((addr) => addr.toString()), amountList.map((amount) => amount.toBigInt())], GAS.BATCH_MINT);
    }
    async redeemAtMaturityByPartition(security, partitionId, sourceId, amount, securityId) {
        LogService.logTrace(`Redeeming at maturity by partition to address ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers.Interface(Bond__factory.abi), "redeemAtMaturityByPartition", [sourceId.toString(), partitionId, amount.toBigInt()], GAS.REDEEM_AT_MATURITY_BY_PARTITION_GAS);
    }
    async fullRedeemAtMaturity(security, sourceId, securityId) {
        LogService.logTrace(`Redeeming at maturity by partition to address ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers.Interface(Bond__factory.abi), "fullRedeemAtMaturity", [sourceId.toString()], GAS.FULL_REDEEM_AT_MATURITY_GAS);
    }
}
