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