"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MosaicFlagsResolver = exports.MosaicsResolver = exports.MosaicIdAliasResolver = exports.MosaicIdResolver = void 0;
const symbol_sdk_1 = require("symbol-sdk");
const options_resolver_1 = require("../options-resolver");
const mosaic_service_1 = require("../services/mosaic.service");
const mosaic_validator_1 = require("../validators/mosaic.validator");
const mosaicId_validator_1 = require("../validators/mosaicId.validator");
/**
 * MosaicId resolver
 */
class MosaicIdResolver {
    /**
     * Resolves a mosaic id provided by the user.
     * @param {Options} options - Command options.
     * @param {string} altText - Alternative text.
     * @param {string} altKey - Alternative key.
     * @returns {Promise<MosaicId>}
     */
    async resolve(options, altText, altKey) {
        const resolution = await (0, options_resolver_1.OptionsResolver)(options, altKey ? altKey : 'mosaicId', () => undefined, altText ? altText : 'Enter the mosaic id in hexadecimal format:', 'text', new mosaicId_validator_1.MosaicIdValidator());
        return new symbol_sdk_1.MosaicId(resolution);
    }
}
exports.MosaicIdResolver = MosaicIdResolver;
/**
 * MosaicId alias resolver
 */
class MosaicIdAliasResolver {
    /**
     * Resolves a mosaic id alias provided by the user.
     * @param {Options} options - Command options.
     * @param {string} altText - Alternative text.
     * @param {string} altKey - Alternative key.
     * @returns {Promise<MosaicId | NamespaceId>}
     */
    async resolve(options, altText, altKey) {
        const resolution = await (0, options_resolver_1.OptionsResolver)(options, altKey ? altKey : 'mosaicId', () => undefined, altText ? altText : 'Enter the mosaic id or alias:', 'text', new mosaicId_validator_1.MosaicIdAliasValidator());
        return mosaic_service_1.MosaicService.getMosaicId(resolution);
    }
    /**
     * Resolves an optional mosaic id or alias provided by the user.
     * @param {any} options - Command options.
     * @param {string} altKey - Alternative key.
     * @param {MosaicId | NamespaceId} defaultValue - Default value.
     */
    optionalResolve(options, altKey, defaultValue) {
        const key = altKey ? altKey : 'referenceMosaicId';
        if (defaultValue) {
            options[key] = options[key] ? options[key] : defaultValue;
        }
        new mosaicId_validator_1.MosaicIdAliasValidator().validate(options[key]);
        return mosaic_service_1.MosaicService.getMosaicId(options[key]);
    }
}
exports.MosaicIdAliasResolver = MosaicIdAliasResolver;
/**
 * Mosaics resolver
 */
class MosaicsResolver {
    /**
     * Resolves a set of mosaics provided by the user.
     * @param {Options} options - Command options.
     * @param {string} altText - Alternative text.
     * @param {string} altKey - Alternative key.
     * @returns {Promise<Mosaic[]>}
     */
    async resolve(options, altText, altKey) {
        const resolution = await (0, options_resolver_1.OptionsResolver)(options, altKey ? altKey : 'mosaics', () => undefined, altText
            ? altText
            : 'Mosaics to transfer in the format (mosaicId(hex)|@aliasName)::absoluteAmount,' +
                ' (Ex: sending 1 symbol.xym, @symbol.xym::1000000). Add multiple mosaics separated by commas:', 'text', new mosaic_validator_1.MosaicsValidator());
        return resolution ? mosaic_service_1.MosaicService.getMosaics(resolution) : [];
    }
}
exports.MosaicsResolver = MosaicsResolver;
/**
 * Mosaics flags resolver
 */
class MosaicFlagsResolver {
    /**
     * Resolves mosaic flags by the user.
     * @param {Options} options - Command options.
     * @returns {Promise<MosaicFlags>}
     */
    async resolve(options) {
        return symbol_sdk_1.MosaicFlags.create(await (0, options_resolver_1.OptionsConfirmResolver)(options, 'supplyMutable', 'Do you want this mosaic to have a mutable supply?'), await (0, options_resolver_1.OptionsConfirmResolver)(options, 'transferable', 'Do you want this mosaic to be transferable?'), await (0, options_resolver_1.OptionsConfirmResolver)(options, 'restrictable', 'Do you want this mosaic to be restrictable?'));
    }
}
exports.MosaicFlagsResolver = MosaicFlagsResolver;
