"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.RoleOperations = 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 RoleOperations {
    executor;
    constructor(executor) {
        this.executor = executor;
    }
    async grantRole(security, targetId, role, securityId) {
        LogService_1.default.logTrace(`Granting role ${role.toString()} to account: ${targetId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers_1.ethers.Interface(asset_tokenization_contracts_1.AccessControlFacet__factory.abi), "grantRole", [role, targetId.toString()], Constants_1.GAS.GRANT_ROLES);
    }
    async applyRoles(security, targetId, roles, actives, securityId) {
        let gas = roles.length * Constants_1.GAS.GRANT_ROLES;
        gas = gas > Constants_1.GAS.MAX_ROLES ? Constants_1.GAS.MAX_ROLES : gas;
        return this.executor.executeContractCall(securityId.toString(), new ethers_1.ethers.Interface(asset_tokenization_contracts_1.AccessControlFacet__factory.abi), "applyRoles", [roles, actives, targetId.toString()], gas);
    }
    async revokeRole(security, targetId, role, securityId) {
        LogService_1.default.logTrace(`Revoking role ${role.toString()} to account: ${targetId.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers_1.ethers.Interface(asset_tokenization_contracts_1.AccessControlFacet__factory.abi), "revokeRole", [role, targetId.toString()], Constants_1.GAS.GRANT_ROLES);
    }
    async renounceRole(security, role, securityId) {
        LogService_1.default.logTrace(`Renounce role ${role.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), new ethers_1.ethers.Interface(asset_tokenization_contracts_1.AccessControlFacet__factory.abi), "renounceRole", [role], Constants_1.GAS.RENOUNCE_ROLES);
    }
    async authorizeOperator(security, targetId, securityId) {
        LogService_1.default.logTrace(`authorizing operator: ${targetId.toString()} for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410TokenHolderFacet__factory.createInterface(), "authorizeOperator", [targetId.toString()], Constants_1.GAS.AUTHORIZE_OPERATOR);
    }
    async revokeOperator(security, targetId, securityId) {
        LogService_1.default.logTrace(`revoking operator: ${targetId.toString()} for security ${security.toString()}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410TokenHolderFacet__factory.createInterface(), "revokeOperator", [targetId.toString()], Constants_1.GAS.REVOKE_OPERATOR);
    }
    async authorizeOperatorByPartition(security, targetId, partitionId, securityId) {
        LogService_1.default.logTrace(`authorizing operator: ${targetId.toString()} for security ${security.toString()} and partition ${partitionId}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410TokenHolderFacet__factory.createInterface(), "authorizeOperatorByPartition", [partitionId, targetId.toString()], Constants_1.GAS.AUTHORIZE_OPERATOR);
    }
    async revokeOperatorByPartition(security, targetId, partitionId, securityId) {
        LogService_1.default.logTrace(`revoking operator: ${targetId.toString()} for security ${security.toString()} and partition ${partitionId}`);
        return this.executor.executeContractCall(securityId.toString(), asset_tokenization_contracts_1.ERC1410TokenHolderFacet__factory.createInterface(), "revokeOperatorByPartition", [partitionId, targetId.toString()], Constants_1.GAS.REVOKE_OPERATOR);
    }
}
exports.RoleOperations = RoleOperations;
