"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.TransferOperations = void 0;
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 TransferOperations {
    executor;
    constructor(executor) {
        this.executor = executor;
    }
    async transfer(security, targetId, amount, securityId) {
        LogService_1.default.logTrace(`Transfering ${amount} securities to account ${targetId.toString()}`);
        const basicTransferInfo = {
            to: targetId.toString(),
            value: amount.toHexString(),
        };
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410TokenHolderFacet__factory.createInterface(), "transferByPartition", [Constants_1._PARTITION_ID_1, basicTransferInfo, "0x"], Constants_1.GAS.TRANSFER);
    }
    async transferAndLock(security, targetId, amount, expirationDate, securityId) {
        LogService_1.default.logTrace(`Transfering ${amount} securities to account ${targetId.toString()} and locking them until ${expirationDate.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.TransferAndLockFacet__factory.createInterface(), "transferAndLockByPartition", [Constants_1._PARTITION_ID_1, targetId.toString(), amount.toHexString(), "0x", expirationDate.toHexString()], Constants_1.GAS.TRANSFER_AND_LOCK);
    }
    async redeem(security, amount, securityId) {
        LogService_1.default.logTrace(`Redeeming ${amount} securities from account ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410TokenHolderFacet__factory.createInterface(), "redeemByPartition", [Constants_1._PARTITION_ID_1, amount.toHexString(), "0x"], Constants_1.GAS.REDEEM);
    }
    async burn(security, source, amount, securityId) {
        LogService_1.default.logTrace(`Burning ${amount} securities from account ${source.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643OperationsFacet__factory.createInterface(), "burn", [source.toString(), amount.toHexString()], Constants_1.GAS.BURN);
    }
    async controllerTransfer(security, sourceId, targetId, amount, securityId) {
        LogService_1.default.logTrace(`Controller transfer ${amount} tokens from account ${sourceId.toString()} to account ${targetId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410ManagementFacet__factory.createInterface(), "controllerTransferByPartition", [Constants_1._PARTITION_ID_1, sourceId.toString(), targetId.toString(), amount.toHexString(), "0x", "0x"], Constants_1.GAS.CONTROLLER_TRANSFER);
    }
    async forcedTransfer(security, source, target, amount, securityId) {
        LogService_1.default.logTrace(`Forced transfer ${amount} tokens from account ${source.toString()} to account ${target.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643OperationsFacet__factory.createInterface(), "forcedTransfer", [source.toString(), target.toString(), amount.toHexString()], Constants_1.GAS.FORCED_TRANSFER);
    }
    async controllerRedeem(security, sourceId, amount, securityId) {
        LogService_1.default.logTrace(`Force redeem ${amount} tokens from account ${sourceId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410ManagementFacet__factory.createInterface(), "controllerRedeemByPartition", [Constants_1._PARTITION_ID_1, sourceId.toString(), amount.toHexString(), "0x", "0x"], Constants_1.GAS.CONTROLLER_REDEEM);
    }
    async operatorTransferByPartition(security, sourceId, targetId, amount, partitionId, securityId) {
        LogService_1.default.logTrace(`Transfering ${amount} securities to account ${targetId.toString()} from account ${sourceId.toString()} on partition ${partitionId}`);
        const operatorTransferData = {
            partition: partitionId,
            from: sourceId.toString(),
            to: targetId.toString(),
            value: amount.toHexString(),
            data: "0x",
            operatorData: "0x",
        };
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410ManagementFacet__factory.createInterface(), "operatorTransferByPartition", [operatorTransferData], Constants_1.GAS.TRANSFER_OPERATOR);
    }
    async batchTransfer(security, amountList, toList, securityId) {
        LogService_1.default.logTrace(`Batch transferring ${amountList.length} tokens from ${security.toString()} to ${toList.map((item) => item.toString())}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643BatchFacet__factory.createInterface(), "batchTransfer", [toList.map((addr) => addr.toString()), amountList.map((amount) => amount.toBigInt())], Constants_1.GAS.BATCH_TRANSFER);
    }
    async batchForcedTransfer(security, amountList, fromList, toList, securityId) {
        LogService_1.default.logTrace(`Batch forced transferring ${amountList.length} tokens from ${fromList.map((item) => item.toString())} to ${toList.map((item) => item.toString())}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643BatchFacet__factory.createInterface(), "batchForcedTransfer", [
            fromList.map((addr) => addr.toString()),
            toList.map((addr) => addr.toString()),
            amountList.map((amount) => amount.toBigInt()),
        ], Constants_1.GAS.BATCH_FORCED_TRANSFER);
    }
    async batchBurn(security, amountList, targetList, securityId) {
        LogService_1.default.logTrace(`Batch burning ${amountList.length} tokens from ${targetList.map((item) => item.toString())}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643BatchFacet__factory.createInterface(), "batchBurn", [targetList.map((addr) => addr.toString()), amountList.map((amount) => amount.toBigInt())], Constants_1.GAS.BATCH_BURN);
    }
}
exports.TransferOperations = TransferOperations;
