"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.ComplianceOperations = 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 ComplianceOperations {
    executor;
    constructor(executor) {
        this.executor = executor;
    }
    async grantKyc(security, targetId, vcBase64, validFrom, validTo, issuer, securityId) {
        LogService_1.default.logTrace(`Granting KYC from issuer ${issuer.toString()} to address ${targetId.toString()} with VC ${vcBase64}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.KycFacet__factory.createInterface(), "grantKyc", [targetId.toString(), vcBase64, validFrom.toBigInt(), validTo.toBigInt(), issuer.toString()], Constants_1.GAS.GRANT_KYC);
    }
    async revokeKyc(security, targetId, securityId) {
        LogService_1.default.logTrace(`Revoking KYC to address ${targetId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.KycFacet__factory.createInterface(), "revokeKyc", [targetId.toString()], Constants_1.GAS.REVOKE_KYC);
    }
    async addIssuer(security, issuer, securityId) {
        LogService_1.default.logTrace(`Adding issuer ${issuer}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.SsiManagementFacet__factory.createInterface(), "addIssuer", [issuer.toString()], Constants_1.GAS.ADD_ISSUER);
    }
    async removeIssuer(security, issuer, securityId) {
        LogService_1.default.logTrace(`Removing issuer ${issuer}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.SsiManagementFacet__factory.createInterface(), "removeIssuer", [issuer.toString()], Constants_1.GAS.REMOVE_ISSUER);
    }
    async setRevocationRegistryAddress(security, revocationRegistry, securityId) {
        LogService_1.default.logTrace(`Setting revocation registry address ${revocationRegistry}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.SsiManagementFacet__factory.createInterface(), "setRevocationRegistryAddress", [revocationRegistry.toString()], Constants_1.GAS.SET_REVOCATION_REGISTRY);
    }
    async activateInternalKyc(security, securityId) {
        LogService_1.default.logTrace(`Activate Internal Kyc to address ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers_1.ethers.Interface(["function activateInternalKyc()"]), "activateInternalKyc", [], Constants_1.GAS.ACTIVATE_INTERNAL_KYC);
    }
    async deactivateInternalKyc(security, securityId) {
        LogService_1.default.logTrace(`Deactivate Internal Kyc to address ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers_1.ethers.Interface(["function deactivateInternalKyc()"]), "deactivateInternalKyc", [], Constants_1.GAS.DEACTIVATE_INTERNAL_KYC);
    }
    async setOnchainID(security, onchainID, securityId) {
        LogService_1.default.logTrace(`Setting onchainID to ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643ManagementFacet__factory.createInterface(), "setOnchainID", [onchainID.toString()], Constants_1.GAS.SET_ONCHAIN_ID);
    }
    async setIdentityRegistry(security, identityRegistry, securityId) {
        LogService_1.default.logTrace(`Setting identity registry to ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643ManagementFacet__factory.createInterface(), "setIdentityRegistry", [identityRegistry.toString()], Constants_1.GAS.SET_IDENTITY_REGISTRY);
    }
    async setCompliance(security, compliance, securityId) {
        LogService_1.default.logTrace(`Setting compliance to ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC3643ManagementFacet__factory.createInterface(), "setCompliance", [compliance.toString()], Constants_1.GAS.SET_COMPLIANCE);
    }
    async updateExternalKycLists(security, externalKycListsAddresses, actives, securityId) {
        LogService_1.default.logTrace(`Updating External Kyc Lists for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ExternalKycListManagementFacet__factory.createInterface(), "updateExternalKycLists", [externalKycListsAddresses.map((address) => address.toString()), actives], Constants_1.GAS.UPDATE_EXTERNAL_KYC_LISTS);
    }
    async addExternalKycList(security, externalKycListAddress, securityId) {
        LogService_1.default.logTrace(`Adding External kyc Lists for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ExternalKycListManagementFacet__factory.createInterface(), "addExternalKycList", [externalKycListAddress.toString()], Constants_1.GAS.ADD_EXTERNAL_KYC_LIST);
    }
    async removeExternalKycList(security, externalKycListAddress, securityId) {
        LogService_1.default.logTrace(`Removing External kyc Lists for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ExternalKycListManagementFacet__factory.createInterface(), "removeExternalKycList", [externalKycListAddress.toString()], Constants_1.GAS.REMOVE_EXTERNAL_KYC_LIST);
    }
    async grantKycMock(contract, targetId, contractId) {
        LogService_1.default.logTrace(`Grant kyc address ${targetId.toString()} to external kyc mock ${contract.toString()}`);
        return this.executor.executeContractCall(contractId.toString(), asset_tokenization_contracts_1.MockedExternalKycList__factory.createInterface(), "grantKyc", [targetId.toString()], Constants_1.GAS.GRANT_KYC_MOCK);
    }
    async revokeKycMock(contract, targetId, contractId) {
        LogService_1.default.logTrace(`Revoke kyc address ${targetId.toString()} to external kyc mock ${contract.toString()}`);
        return this.executor.executeContractCall(contractId.toString(), asset_tokenization_contracts_1.MockedExternalKycList__factory.createInterface(), "revokeKyc", [targetId.toString()], Constants_1.GAS.REVOKE_KYC_MOCK);
    }
    async createExternalKycListMock() {
        LogService_1.default.logTrace(`Deploying External Kyc List List Mock contract`);
        return this.executor.deployContract(asset_tokenization_contracts_1.MockedExternalKycList__factory.bytecode, Constants_1.GAS.CREATE_EXTERNAL_KYC_LIST_MOCK);
    }
}
exports.ComplianceOperations = ComplianceOperations;
