"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.removePrimaryIssuanceAgent = exports.getAuthorization = exports.prepareRemovePrimaryIssuanceAgent = void 0;
const internal_1 = require("../../internal");
const types_1 = require("../../types");
const conversion_1 = require("../../utils/conversion");
/**
 * @hidden
 *
 * @deprecated
 */
function prepareRemovePrimaryIssuanceAgent(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const { context: { polymeshApi: { tx: { externalAgents }, }, }, context, } = this;
        const { ticker } = args;
        const securityToken = new internal_1.SecurityToken({ ticker }, context);
        const { primaryIssuanceAgents } = yield securityToken.details();
        if (primaryIssuanceAgents.length !== 1) {
            throw new internal_1.PolymeshError({
                code: types_1.ErrorCode.UnmetPrerequisite,
                message: 'There must be one (and only one) Primary Issuance Agent assigned to this Security Token',
            });
        }
        const rawTicker = conversion_1.stringToTicker(ticker, context);
        const rawIdentityId = conversion_1.stringToIdentityId(primaryIssuanceAgents[0].did, context);
        this.addTransaction(externalAgents.removeAgent, {}, rawTicker, rawIdentityId);
    });
}
exports.prepareRemovePrimaryIssuanceAgent = prepareRemovePrimaryIssuanceAgent;
/**
 * @hidden
 */
function getAuthorization({ ticker }) {
    return {
        permissions: {
            transactions: [types_1.TxTags.externalAgents.RemoveAgent],
            tokens: [new internal_1.SecurityToken({ ticker }, this.context)],
            portfolios: [],
        },
    };
}
exports.getAuthorization = getAuthorization;
/**
 * @hidden
 */
const removePrimaryIssuanceAgent = () => new internal_1.Procedure(prepareRemovePrimaryIssuanceAgent, getAuthorization);
exports.removePrimaryIssuanceAgent = removePrimaryIssuanceAgent;
//# sourceMappingURL=removePrimaryIssuanceAgent.js.map