"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.SecurityMetadataOperations = 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 SecurityMetadataOperations {
    executor;
    constructor(executor) {
        this.executor = executor;
    }
    async setName(security, name, securityId) {
        LogService_1.default.logTrace(`Setting name to ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643ManagementFacet__factory.createInterface(), "setName", [name], Constants_1.GAS.SET_NAME);
    }
    async setSymbol(security, symbol, securityId) {
        LogService_1.default.logTrace(`Setting symbol to ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643ManagementFacet__factory.createInterface(), "setSymbol", [symbol], Constants_1.GAS.SET_SYMBOL);
    }
    async setDocument(security, name, uri, hash, securityId) {
        LogService_1.default.logTrace(`Setting document: ${name}, with ${uri}, and hash ${hash} for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1643Facet__factory.createInterface(), "setDocument", [name, uri, hash], Constants_1.GAS.SET_DOCUMENT);
    }
    async removeDocument(security, name, securityId) {
        LogService_1.default.logTrace(`Removing document: ${name} for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1643Facet__factory.createInterface(), "removeDocument", [name], Constants_1.GAS.REMOVE_DOCUMENT);
    }
    async updateConfigVersion(security, configVersion, securityId) {
        LogService_1.default.logTrace(`Updating config version`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.DiamondFacet__factory.createInterface(), "updateConfigVersion", [configVersion], Constants_1.GAS.UPDATE_CONFIG_VERSION);
    }
    async updateConfig(security, configId, configVersion, securityId) {
        LogService_1.default.logTrace(`Updating config`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.DiamondFacet__factory.createInterface(), "updateConfig", [configId, configVersion], Constants_1.GAS.UPDATE_CONFIG);
    }
    async updateResolver(security, resolver, configVersion, configId, securityId) {
        LogService_1.default.logTrace(`Updating Resolver`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.DiamondFacet__factory.createInterface(), "updateResolver", [resolver.toString(), configId, configVersion], Constants_1.GAS.UPDATE_RESOLVER);
    }
    async protectPartitions(security, securityId) {
        LogService_1.default.logTrace(`Protecting Partitions for security: ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers_1.ethers.Interface(["function protectPartitions()"]), "protectPartitions", [], Constants_1.GAS.PROTECT_PARTITION);
    }
    async unprotectPartitions(security, securityId) {
        LogService_1.default.logTrace(`Unprotecting Partitions for security: ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers_1.ethers.Interface(["function unprotectPartitions()"]), "unprotectPartitions", [], Constants_1.GAS.UNPROTECT_PARTITION);
    }
    async protectedRedeemFromByPartition(security, partitionId, sourceId, amount, deadline, nounce, signature, securityId) {
        LogService_1.default.logTrace(`Protected Redeeming ${amount} securities from account ${sourceId.toString()}`);
        const protectionData = {
            deadline: deadline.toBigInt(),
            nounce: nounce.toBigInt(),
            signature: signature,
        };
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410ManagementFacet__factory.createInterface(), "protectedRedeemFromByPartition", [partitionId, sourceId.toString(), amount.toBigInt(), protectionData], Constants_1.GAS.PROTECTED_REDEEM);
    }
    async protectedTransferFromByPartition(security, partitionId, sourceId, targetId, amount, deadline, nounce, signature, securityId) {
        LogService_1.default.logTrace(`Protected Transfering ${amount} securities from account ${sourceId.toString()} to account ${targetId.toString()}`);
        const protectionData = {
            deadline: deadline.toBigInt(),
            nounce: nounce.toBigInt(),
            signature: signature,
        };
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410ManagementFacet__factory.createInterface(), "protectedTransferFromByPartition", [partitionId, sourceId.toString(), targetId.toString(), amount.toBigInt(), protectionData], Constants_1.GAS.PROTECTED_TRANSFER);
    }
    async freezePartialTokens(security, amount, targetId, securityId) {
        LogService_1.default.logTrace(`Freezing ${amount} tokens ${security.toString()} to account ${targetId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.FreezeFacet__factory.createInterface(), "freezePartialTokens", [targetId.toString(), amount.toBigInt()], Constants_1.GAS.FREEZE_PARTIAL_TOKENS);
    }
    async unfreezePartialTokens(security, amount, targetId, securityId) {
        LogService_1.default.logTrace(`Unfreezing ${amount} tokens ${security.toString()} to account ${targetId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.FreezeFacet__factory.createInterface(), "unfreezePartialTokens", [targetId.toString(), amount.toBigInt()], Constants_1.GAS.UNFREEZE_PARTIAL_TOKENS);
    }
    async setAddressFrozen(security, status, target, securityId) {
        LogService_1.default.logTrace(`Freezing address ${target.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.FreezeFacet__factory.createInterface(), "setAddressFrozen", [target.toString(), status], Constants_1.GAS.SET_ADDRESS_FROZEN);
    }
    async batchSetAddressFrozen(security, freezeList, targetList, securityId) {
        LogService_1.default.logTrace(`Batch setting freeze status for ${targetList.length} addresses`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.FreezeFacet__factory.createInterface(), "batchSetAddressFrozen", [targetList.map((addr) => addr.toString()), freezeList], Constants_1.GAS.BATCH_SET_ADDRESS_FROZEN);
    }
    async batchFreezePartialTokens(security, amountList, targetList, securityId) {
        LogService_1.default.logTrace(`Batch freezing partial tokens for ${targetList.length} addresses`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.FreezeFacet__factory.createInterface(), "batchFreezePartialTokens", [targetList.map((addr) => addr.toString()), amountList.map((amount) => amount.toBigInt())], Constants_1.GAS.BATCH_FREEZE_PARTIAL_TOKENS);
    }
    async batchUnfreezePartialTokens(security, amountList, targetList, securityId) {
        LogService_1.default.logTrace(`Batch unfreezing partial tokens for ${targetList.length} addresses`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.FreezeFacet__factory.createInterface(), "batchUnfreezePartialTokens", [targetList.map((addr) => addr.toString()), amountList.map((amount) => amount.toBigInt())], Constants_1.GAS.BATCH_UNFREEZE_PARTIAL_TOKENS);
    }
    async recoveryAddress(security, lostWalletId, newWalletId, securityId) {
        LogService_1.default.logTrace(`Recovering address ${lostWalletId.toString()} to ${newWalletId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643ManagementFacet__factory.createInterface(), "recoveryAddress", [lostWalletId.toString(), newWalletId.toString(), Constants_1.EVM_ZERO_ADDRESS], Constants_1.GAS.RECOVERY_ADDRESS);
    }
    async addAgent(security, agentId, securityId) {
        LogService_1.default.logTrace(`Granting agent role to ${agentId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643ManagementFacet__factory.createInterface(), "addAgent", [agentId.toString()], Constants_1.GAS.ADD_AGENT);
    }
    async removeAgent(security, agentId, securityId) {
        LogService_1.default.logTrace(`Revoking agent role from ${agentId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643ManagementFacet__factory.createInterface(), "removeAgent", [agentId.toString()], Constants_1.GAS.REMOVE_AGENT);
    }
    async setMaxSupply(security, maxSupply, securityId) {
        LogService_1.default.logTrace(`Setting max supply ${maxSupply} for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.CapFacet__factory.createInterface(), "setMaxSupply", [maxSupply.toHexString()], Constants_1.GAS.SET_MAX_SUPPLY);
    }
    async setNominalValue(security, nominalValue, nominalValueDecimals, securityId) {
        LogService_1.default.logTrace(`Setting nominal value for security: ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.NominalValue__factory.createInterface(), "setNominalValue", [nominalValue, nominalValueDecimals], Constants_1.GAS.SET_NOMINAL_VALUE);
    }
}
exports.SecurityMetadataOperations = SecurityMetadataOperations;
