"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.KnownPermissionGroup = void 0;
const internal_1 = require("../../internal");
const types_1 = require("../../types");
const conversion_1 = require("../../utils/conversion");
const internal_2 = require("../../utils/internal");
/**
 * Represents a pre-defined group of permissions for a Security Token
 */
class KnownPermissionGroup extends internal_1.PermissionGroup {
    /**
     * @hidden
     */
    constructor(identifiers, context) {
        super(identifiers, context);
        const { type } = identifiers;
        this.type = type;
    }
    /**
     * @hidden
     * Check if a value is of type [[UniqueIdentifiers]]
     */
    static isUniqueIdentifiers(identifier) {
        const { type, ticker } = identifier;
        return type in types_1.PermissionGroupType && typeof ticker === 'string';
    }
    /**
     * Retrieve the Permissions associated with this Permission Group
     */
    getPermissions() {
        return __awaiter(this, void 0, void 0, function* () {
            const { type } = this;
            let transactions;
            switch (type) {
                case types_1.PermissionGroupType.ExceptMeta:
                    transactions = { values: [types_1.ModuleName.ExternalAgents], type: types_1.PermissionType.Exclude };
                    break;
                case types_1.PermissionGroupType.PolymeshV1Caa:
                    transactions = {
                        values: [
                            types_1.ModuleName.CapitalDistribution,
                            types_1.ModuleName.CorporateAction,
                            types_1.ModuleName.CorporateBallot,
                        ],
                        type: types_1.PermissionType.Include,
                    };
                    break;
                case types_1.PermissionGroupType.PolymeshV1Pia:
                    transactions = {
                        values: [
                            types_1.TxTags.asset.ControllerTransfer,
                            types_1.TxTags.asset.Issue,
                            types_1.TxTags.asset.Redeem,
                            types_1.ModuleName.Sto,
                        ],
                        exceptions: [types_1.TxTags.sto.Invest],
                        type: types_1.PermissionType.Include,
                    };
                    break;
                default:
                    transactions = null;
                    break;
            }
            return {
                transactions,
                transactionGroups: transactions ? conversion_1.transactionPermissionsToTxGroups(transactions) : [],
            };
        });
    }
    /**
     * Determine whether this Known Permission Group exists on chain
     */
    exists() {
        return __awaiter(this, void 0, void 0, function* () {
            return true;
        });
    }
    /**
     * Return the KnownPermissionGroup's static data
     */
    toJson() {
        const { type, token } = this;
        return internal_2.toHumanReadable({
            type,
            ticker: token,
        });
    }
}
exports.KnownPermissionGroup = KnownPermissionGroup;
//# sourceMappingURL=KnownPermissionGroup.js.map