"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.removeCorporateActionsAgent = exports.getAuthorization = exports.prepareRemoveCorporateActionsAgent = void 0;
const internal_1 = require("../../internal");
const types_1 = require("../../types");
const conversion_1 = require("../../utils/conversion");
/**
 * @hidden
 *
 * @deprecated
 */
function prepareRemoveCorporateActionsAgent(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const { context: { polymeshApi: { tx: { externalAgents }, }, }, context, } = this;
        const { ticker } = args;
        const asset = new internal_1.Asset({ ticker }, context);
        const agents = yield asset.corporateActions.getAgents();
        if (agents.length !== 1) {
            throw new internal_1.PolymeshError({
                code: types_1.ErrorCode.UnmetPrerequisite,
                message: 'There must be one (and only one) Corporate Actions Agent assigned to this Asset',
            });
        }
        const rawTicker = conversion_1.stringToTicker(ticker, context);
        const rawIdentityId = conversion_1.stringToIdentityId(agents[0].did, context);
        this.addTransaction({
            transaction: externalAgents.removeAgent,
            args: [rawTicker, rawIdentityId],
        });
    });
}
exports.prepareRemoveCorporateActionsAgent = prepareRemoveCorporateActionsAgent;
/**
 * @hidden
 */
function getAuthorization({ ticker }) {
    return {
        permissions: {
            transactions: [types_1.TxTags.externalAgents.RemoveAgent],
            assets: [new internal_1.Asset({ ticker }, this.context)],
            portfolios: [],
        },
    };
}
exports.getAuthorization = getAuthorization;
/**
 * @hidden
 */
const removeCorporateActionsAgent = () => new internal_1.Procedure(prepareRemoveCorporateActionsAgent, getAuthorization);
exports.removeCorporateActionsAgent = removeCorporateActionsAgent;
//# sourceMappingURL=removeCorporateActionsAgent.js.map