"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NamespaceTypeResolver = exports.NamespaceIdResolver = exports.NamespaceNameStringResolver = exports.NamespaceNameResolver = void 0;
const symbol_sdk_1 = require("symbol-sdk");
const options_resolver_1 = require("../options-resolver");
const namespaceId_validator_1 = require("../validators/namespaceId.validator");
/**
 * Namespace name resolver
 */
class NamespaceNameResolver {
    /**
     * Resolves a namespace name provided by the user.
     * @param {Options} options - Command options.
     * @param {string} altText - Alternative text.
     * @param {string} altKey - Alternative key.
     * @returns {Promise<NamespaceId>}
     */
    async resolve(options, altText, altKey) {
        const resolution = await (0, options_resolver_1.OptionsResolver)(options, altKey ? altKey : 'namespaceName', () => undefined, altText ? altText : 'Enter the namespace name:', 'text', undefined);
        return new symbol_sdk_1.NamespaceId(resolution);
    }
}
exports.NamespaceNameResolver = NamespaceNameResolver;
/**
 * Namespace name string resolver
 */
class NamespaceNameStringResolver {
    /**
     * Resolves a namespace name provided by the user.
     * @param {Options} options - Command options.
     * @param {string} altText - Alternative text.
     * @param {string} altKey - Alternative key.
     * @returns {Promise<string>}
     */
    async resolve(options, altText, altKey) {
        const resolution = await (0, options_resolver_1.OptionsResolver)(options, altKey ? altKey : 'namespaceName', () => undefined, altText ? altText : 'Enter the namespace name:', 'text', undefined);
        return resolution;
    }
}
exports.NamespaceNameStringResolver = NamespaceNameStringResolver;
/**
 * Namespace id resolver
 */
class NamespaceIdResolver {
    /**
     * Resolves a namespace id provided by the user.
     * @param {Options} options - Command options.
     * @param {string} altText - Alternative text.
     * @param {string} altKey - Alternative key.
     * @returns {Promise<NamespaceId>}
     */
    async resolve(options, altText, altKey) {
        const resolution = await (0, options_resolver_1.OptionsResolver)(options, altKey ? altKey : 'namespaceId', () => undefined, altText ? altText : 'Enter the namespace id in hexadecimal:', 'text', new namespaceId_validator_1.NamespaceIdValidator());
        const namespaceIdUInt64 = symbol_sdk_1.UInt64.fromHex(resolution);
        return new symbol_sdk_1.NamespaceId([namespaceIdUInt64.lower, namespaceIdUInt64.higher]);
    }
}
exports.NamespaceIdResolver = NamespaceIdResolver;
/**
 * Namespace type resolver
 */
class NamespaceTypeResolver {
    /**
     * Resolves the namespace type.
     * @param {Options} options - Command options.
     * @param {string} altText - Alternative text.
     * @returns {Promise<NamespaceRegistrationType>}
     */
    async resolve(options, altText) {
        if (!options.subnamespace) {
            const resolution = await (0, options_resolver_1.OptionsConfirmResolver)(options, 'rootnamespace', altText ? altText : 'Do you want to create a root namespace?');
            if (resolution) {
                options.rootnamespace = true;
            }
        }
        let namespaceType = symbol_sdk_1.NamespaceRegistrationType.SubNamespace;
        if (options.rootnamespace) {
            namespaceType = symbol_sdk_1.NamespaceRegistrationType.RootNamespace;
        }
        return namespaceType;
    }
}
exports.NamespaceTypeResolver = NamespaceTypeResolver;
