"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.transferTokenOwnership = exports.getAuthorization = exports.prepareTransferTokenOwnership = void 0;
const internal_1 = require("../../internal");
const types_1 = require("../../types");
const conversion_1 = require("../../utils/conversion");
/**
 * @hidden
 */
function prepareTransferTokenOwnership(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const { context: { polymeshApi: { tx }, }, context, } = this;
        const { ticker, target, expiry } = args;
        const rawSignatory = conversion_1.signerValueToSignatory({ type: types_1.SignerType.Identity, value: conversion_1.signerToString(target) }, context);
        const rawAuthorizationData = conversion_1.authorizationToAuthorizationData({ type: types_1.AuthorizationType.TransferAssetOwnership, value: ticker }, context);
        const rawExpiry = expiry ? conversion_1.dateToMoment(expiry, context) : null;
        this.addTransaction(tx.identity.addAuthorization, {}, rawSignatory, rawAuthorizationData, rawExpiry);
        return new internal_1.SecurityToken({ ticker }, context);
    });
}
exports.prepareTransferTokenOwnership = prepareTransferTokenOwnership;
/**
 * @hidden
 */
function getAuthorization({ ticker }) {
    return {
        permissions: {
            tokens: [new internal_1.SecurityToken({ ticker }, this.context)],
            transactions: [types_1.TxTags.identity.AddAuthorization],
            portfolios: [],
        },
    };
}
exports.getAuthorization = getAuthorization;
/**
 * @hidden
 */
const transferTokenOwnership = () => new internal_1.Procedure(prepareTransferTokenOwnership, getAuthorization);
exports.transferTokenOwnership = transferTokenOwnership;
//# sourceMappingURL=transferTokenOwnership.js.map