"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.togglePauseRequirements = exports.getAuthorization = exports.prepareTogglePauseRequirements = void 0;
const internal_1 = require("../../internal");
const types_1 = require("../../types");
const conversion_1 = require("../../utils/conversion");
/**
 * @hidden
 */
function prepareTogglePauseRequirements(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const { context: { polymeshApi: { query, tx }, }, context, } = this;
        const { ticker, pause } = args;
        const rawTicker = conversion_1.stringToTicker(ticker, context);
        const { paused } = yield query.complianceManager.assetCompliances(rawTicker);
        if (pause === conversion_1.boolToBoolean(paused)) {
            throw new internal_1.PolymeshError({
                code: types_1.ErrorCode.ValidationError,
                message: `Requirements are already ${paused ? '' : 'un'}paused`,
            });
        }
        this.addTransaction(pause ? tx.complianceManager.pauseAssetCompliance : tx.complianceManager.resumeAssetCompliance, {}, rawTicker);
        return new internal_1.SecurityToken({ ticker }, context);
    });
}
exports.prepareTogglePauseRequirements = prepareTogglePauseRequirements;
/**
 * @hidden
 */
function getAuthorization({ ticker, pause }) {
    return {
        permissions: {
            transactions: [
                pause
                    ? types_1.TxTags.complianceManager.PauseAssetCompliance
                    : types_1.TxTags.complianceManager.ResumeAssetCompliance,
            ],
            tokens: [new internal_1.SecurityToken({ ticker }, this.context)],
            portfolios: [],
        },
    };
}
exports.getAuthorization = getAuthorization;
/**
 * @hidden
 */
const togglePauseRequirements = () => new internal_1.Procedure(prepareTogglePauseRequirements, getAuthorization);
exports.togglePauseRequirements = togglePauseRequirements;
//# sourceMappingURL=togglePauseRequirements.js.map