// SPDX-License-Identifier: Apache-2.0
import { ethers } from "ethers";
import { KycFacet__factory, SsiManagementFacet__factory, ERC3643ManagementFacet__factory, ExternalKycListManagementFacet__factory, MockedExternalKycList__factory, } from "@hashgraph/asset-tokenization-contracts";
import { GAS } from "../../../../core/Constants";
import LogService from "../../../../app/service/log/LogService";
export class ComplianceOperations {
    executor;
    constructor(executor) {
        this.executor = executor;
    }
    async grantKyc(security, targetId, vcBase64, validFrom, validTo, issuer, securityId) {
        LogService.logTrace(`Granting KYC from issuer ${issuer.toString()} to address ${targetId.toString()} with VC ${vcBase64}`);
        return this.executor.executeContractCall(securityId.toString(), KycFacet__factory.createInterface(), "grantKyc", [targetId.toString(), vcBase64, validFrom.toBigInt(), validTo.toBigInt(), issuer.toString()], GAS.GRANT_KYC);
    }
    async revokeKyc(security, targetId, securityId) {
        LogService.logTrace(`Revoking KYC to address ${targetId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), KycFacet__factory.createInterface(), "revokeKyc", [targetId.toString()], GAS.REVOKE_KYC);
    }
    async addIssuer(security, issuer, securityId) {
        LogService.logTrace(`Adding issuer ${issuer}`);
        return this.executor.executeContractCall(securityId.toString(), SsiManagementFacet__factory.createInterface(), "addIssuer", [issuer.toString()], GAS.ADD_ISSUER);
    }
    async removeIssuer(security, issuer, securityId) {
        LogService.logTrace(`Removing issuer ${issuer}`);
        return this.executor.executeContractCall(securityId.toString(), SsiManagementFacet__factory.createInterface(), "removeIssuer", [issuer.toString()], GAS.REMOVE_ISSUER);
    }
    async setRevocationRegistryAddress(security, revocationRegistry, securityId) {
        LogService.logTrace(`Setting revocation registry address ${revocationRegistry}`);
        return this.executor.executeContractCall(securityId.toString(), SsiManagementFacet__factory.createInterface(), "setRevocationRegistryAddress", [revocationRegistry.toString()], GAS.SET_REVOCATION_REGISTRY);
    }
    async activateInternalKyc(security, securityId) {
        LogService.logTrace(`Activate Internal Kyc to address ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers.Interface(["function activateInternalKyc()"]), "activateInternalKyc", [], GAS.ACTIVATE_INTERNAL_KYC);
    }
    async deactivateInternalKyc(security, securityId) {
        LogService.logTrace(`Deactivate Internal Kyc to address ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers.Interface(["function deactivateInternalKyc()"]), "deactivateInternalKyc", [], GAS.DEACTIVATE_INTERNAL_KYC);
    }
    async setOnchainID(security, onchainID, securityId) {
        LogService.logTrace(`Setting onchainID to ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), ERC3643ManagementFacet__factory.createInterface(), "setOnchainID", [onchainID.toString()], GAS.SET_ONCHAIN_ID);
    }
    async setIdentityRegistry(security, identityRegistry, securityId) {
        LogService.logTrace(`Setting identity registry to ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), ERC3643ManagementFacet__factory.createInterface(), "setIdentityRegistry", [identityRegistry.toString()], GAS.SET_IDENTITY_REGISTRY);
    }
    async setCompliance(security, compliance, securityId) {
        LogService.logTrace(`Setting compliance to ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), ERC3643ManagementFacet__factory.createInterface(), "setCompliance", [compliance.toString()], GAS.SET_COMPLIANCE);
    }
    async updateExternalKycLists(security, externalKycListsAddresses, actives, securityId) {
        LogService.logTrace(`Updating External Kyc Lists for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), ExternalKycListManagementFacet__factory.createInterface(), "updateExternalKycLists", [externalKycListsAddresses.map((address) => address.toString()), actives], GAS.UPDATE_EXTERNAL_KYC_LISTS);
    }
    async addExternalKycList(security, externalKycListAddress, securityId) {
        LogService.logTrace(`Adding External kyc Lists for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), ExternalKycListManagementFacet__factory.createInterface(), "addExternalKycList", [externalKycListAddress.toString()], GAS.ADD_EXTERNAL_KYC_LIST);
    }
    async removeExternalKycList(security, externalKycListAddress, securityId) {
        LogService.logTrace(`Removing External kyc Lists for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), ExternalKycListManagementFacet__factory.createInterface(), "removeExternalKycList", [externalKycListAddress.toString()], GAS.REMOVE_EXTERNAL_KYC_LIST);
    }
    async grantKycMock(contract, targetId, contractId) {
        LogService.logTrace(`Grant kyc address ${targetId.toString()} to external kyc mock ${contract.toString()}`);
        return this.executor.executeContractCall(contractId.toString(), MockedExternalKycList__factory.createInterface(), "grantKyc", [targetId.toString()], GAS.GRANT_KYC_MOCK);
    }
    async revokeKycMock(contract, targetId, contractId) {
        LogService.logTrace(`Revoke kyc address ${targetId.toString()} to external kyc mock ${contract.toString()}`);
        return this.executor.executeContractCall(contractId.toString(), MockedExternalKycList__factory.createInterface(), "revokeKyc", [targetId.toString()], GAS.REVOKE_KYC_MOCK);
    }
    async createExternalKycListMock() {
        LogService.logTrace(`Deploying External Kyc List List Mock contract`);
        return this.executor.deployContract(MockedExternalKycList__factory.bytecode, GAS.CREATE_EXTERNAL_KYC_LIST_MOCK);
    }
}
