"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AddressChoiceResolver = exports.CosignatoryUnresolvedAddressesResolver = exports.UnresolvedAddressResolver = exports.AddressResolver = void 0;
const symbol_sdk_1 = require("symbol-sdk");
const options_resolver_1 = require("../options-resolver");
const account_service_1 = require("../services/account.service");
const address_validator_1 = require("../validators/address.validator");
/**
 * Address resolver
 */
class AddressResolver {
    /**
     * Resolves an address provided by the user.
     * @param {Options} options - Command options.
     * @param {Profile} secondSource - Secondary data source.
     * @param {string} altText - Alternative text.
     * @param {string} altKey - Alternative key.
     * @returns {Promise<Address>}
     */
    async resolve(options, secondSource, altText, altKey) {
        const resolution = await (0, options_resolver_1.OptionsResolver)(options, altKey ? altKey : 'address', () => (secondSource ? secondSource.address.pretty() : undefined), altText ? altText : 'Enter an address:', 'text', new address_validator_1.AddressValidator());
        return symbol_sdk_1.Address.createFromRawAddress(resolution);
    }
}
exports.AddressResolver = AddressResolver;
class UnresolvedAddressResolver {
    /**
     * Resolves an unresolved address provided by the user.
     * @param {ProfileOptions} options - Command options.
     * @param {Profile} secondSource - Secondary data source.
     * @param {string} altText - Alternative text.
     * @param {string} altKey - Alternative key.
     * @returns {Promise<UnresolvedAddress>}
     */
    async resolve(options, secondSource, altText, altKey) {
        const resolution = await (0, options_resolver_1.OptionsResolver)(options, altKey ? altKey : 'address', () => (secondSource ? secondSource.address.pretty() : undefined), altText ? altText : 'Enter an address (or @alias):', 'text', new address_validator_1.UnresolvedAddressValidator());
        return account_service_1.AccountService.getUnresolvedAddress(resolution);
    }
}
exports.UnresolvedAddressResolver = UnresolvedAddressResolver;
/**
 * Cosignatory public key resolver
 */
class CosignatoryUnresolvedAddressesResolver {
    /**
     * Resolves a set of cosignatory addresses provided by the user.
     * @param {Options} options - Command options.
     * @param {Profile} secondSource - Secondary data source.
     * @param {string} altText - Alternative text.
     * @param {string} altKey - Alternative key.
     * @returns {Promise<PublicAccount[]>}
     */
    async resolve(options, secondSource, altText, altKey) {
        const resolution = await (0, options_resolver_1.OptionsResolver)(options, altKey ? altKey : 'cosignatoryAddresses', () => undefined, altText ? altText : 'Enter the cosignatoriesaddresses (separated by a comma):', 'text', new address_validator_1.UnresolvedAddressesValidator());
        const cosignatoryAddresses = resolution.split(',');
        const cosignatories = [];
        cosignatoryAddresses.map((cosignatory) => {
            cosignatories.push(account_service_1.AccountService.getUnresolvedAddress(cosignatory));
        });
        return cosignatories;
    }
}
exports.CosignatoryUnresolvedAddressesResolver = CosignatoryUnresolvedAddressesResolver;
/**
 * Address choice resolver
 */
class AddressChoiceResolver {
    /**
     * Resolves an address from a list of addresses
     * @param {string[]} addresses
     * @returns {Promise<Address>}
     */
    async resolve(addresses) {
        const choices = addresses.map((string) => ({ title: string, value: string }));
        return symbol_sdk_1.Address.createFromRawAddress(await (0, options_resolver_1.OptionsChoiceResolver)({}, 'signer', 'Choose a signer:', choices, 'select', undefined));
    }
}
exports.AddressChoiceResolver = AddressChoiceResolver;
