"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountManagement = void 0;
const internal_1 = require("./internal");
const types_1 = require("./types");
const internal_2 = require("./utils/internal");
/**
 * Handles functionality related to Account Management
 */
class AccountManagement {
    /**
     * @hidden
     */
    constructor(context) {
        this.context = context;
        this.removeSecondaryAccounts = internal_2.createProcedureMethod({
            getProcedureAndArgs: args => [internal_1.removeSecondaryAccounts, Object.assign({}, args)],
        }, context);
        this.revokePermissions = internal_2.createProcedureMethod({
            getProcedureAndArgs: args => {
                const { secondaryAccounts } = args;
                const accounts = secondaryAccounts.map(account => {
                    return {
                        account,
                        permissions: {
                            tokens: { type: types_1.PermissionType.Include, values: [] },
                            transactions: { type: types_1.PermissionType.Include, values: [] },
                            portfolios: { type: types_1.PermissionType.Include, values: [] },
                        },
                    };
                });
                return [internal_1.modifySignerPermissions, { secondaryAccounts: accounts }];
            },
        }, context);
        this.modifyPermissions = internal_2.createProcedureMethod({ getProcedureAndArgs: args => [internal_1.modifySignerPermissions, Object.assign({}, args)] }, context);
        this.inviteAccount = internal_2.createProcedureMethod({ getProcedureAndArgs: args => [internal_1.inviteAccount, Object.assign({}, args)] }, context);
        this.freezeSecondaryAccounts = internal_2.createProcedureMethod({
            getProcedureAndArgs: () => [internal_1.toggleFreezeSecondaryAccounts, { freeze: true }],
            voidArgs: true,
        }, context);
        this.unfreezeSecondaryAccounts = internal_2.createProcedureMethod({
            getProcedureAndArgs: () => [internal_1.toggleFreezeSecondaryAccounts, { freeze: false }],
            voidArgs: true,
        }, context);
        this.subsidizeAccount = internal_2.createProcedureMethod({ getProcedureAndArgs: args => [internal_1.subsidizeAccount, Object.assign({}, args)] }, context);
    }
    // eslint-disable-next-line require-jsdoc
    getAccountBalance(args, callback) {
        const { context } = this;
        let account;
        let cb = callback;
        switch (typeof args) {
            case 'undefined': {
                break;
            }
            case 'function': {
                cb = args;
                break;
            }
            default: {
                ({ account } = args);
                break;
            }
        }
        if (!account) {
            account = context.getCurrentAccount();
        }
        else if (typeof account === 'string') {
            account = new internal_1.Account({ address: account }, context);
        }
        if (cb) {
            return account.getBalance(cb);
        }
        return account.getBalance();
    }
    /**
     * Create an Account instance from an address. If no address is passed, the current Account is returned
     */
    getAccount(args) {
        const { context } = this;
        if (args) {
            return new internal_1.Account(args, context);
        }
        return context.getCurrentAccount();
    }
    /**
     * Return a list that contains all the signing Accounts associated to the SDK instance
     *
     * @throws — if there is no current Account associated to the SDK instance
     */
    getAccounts() {
        return this.context.getAccounts();
    }
}
exports.AccountManagement = AccountManagement;
//# sourceMappingURL=AccountManagement.js.map