// SPDX-License-Identifier: Apache-2.0
import { ethers } from "ethers";
import { AccessControlFacet__factory, ERC1410TokenHolderFacet__factory } from "@hashgraph/asset-tokenization-contracts";
import { GAS } from "../../../../core/Constants";
import LogService from "../../../../app/service/log/LogService";
export class RoleOperations {
    executor;
    constructor(executor) {
        this.executor = executor;
    }
    async grantRole(security, targetId, role, securityId) {
        LogService.logTrace(`Granting role ${role.toString()} to account: ${targetId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers.Interface(AccessControlFacet__factory.abi), "grantRole", [role, targetId.toString()], GAS.GRANT_ROLES);
    }
    async applyRoles(security, targetId, roles, actives, securityId) {
        let gas = roles.length * GAS.GRANT_ROLES;
        gas = gas > GAS.MAX_ROLES ? GAS.MAX_ROLES : gas;
        return this.executor.executeContractCall(securityId.toString(), new ethers.Interface(AccessControlFacet__factory.abi), "applyRoles", [roles, actives, targetId.toString()], gas);
    }
    async revokeRole(security, targetId, role, securityId) {
        LogService.logTrace(`Revoking role ${role.toString()} to account: ${targetId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers.Interface(AccessControlFacet__factory.abi), "revokeRole", [role, targetId.toString()], GAS.GRANT_ROLES);
    }
    async renounceRole(security, role, securityId) {
        LogService.logTrace(`Renounce role ${role.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers.Interface(AccessControlFacet__factory.abi), "renounceRole", [role], GAS.RENOUNCE_ROLES);
    }
    async authorizeOperator(security, targetId, securityId) {
        LogService.logTrace(`authorizing operator: ${targetId.toString()} for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), ERC1410TokenHolderFacet__factory.createInterface(), "authorizeOperator", [targetId.toString()], GAS.AUTHORIZE_OPERATOR);
    }
    async revokeOperator(security, targetId, securityId) {
        LogService.logTrace(`revoking operator: ${targetId.toString()} for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), ERC1410TokenHolderFacet__factory.createInterface(), "revokeOperator", [targetId.toString()], GAS.REVOKE_OPERATOR);
    }
    async authorizeOperatorByPartition(security, targetId, partitionId, securityId) {
        LogService.logTrace(`authorizing operator: ${targetId.toString()} for security ${security.toString()} and partition ${partitionId}`);
        return this.executor.executeContractCall(securityId.toString(), ERC1410TokenHolderFacet__factory.createInterface(), "authorizeOperatorByPartition", [partitionId, targetId.toString()], GAS.AUTHORIZE_OPERATOR);
    }
    async revokeOperatorByPartition(security, targetId, partitionId, securityId) {
        LogService.logTrace(`revoking operator: ${targetId.toString()} for security ${security.toString()} and partition ${partitionId}`);
        return this.executor.executeContractCall(securityId.toString(), ERC1410TokenHolderFacet__factory.createInterface(), "revokeOperatorByPartition", [partitionId, targetId.toString()], GAS.REVOKE_OPERATOR);
    }
}
