"use strict";
/*
 *
 * Copyright 2018-present NEM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.NetworkCurrencyResolver = void 0;
const clime_1 = require("clime");
const symbol_sdk_1 = require("symbol-sdk");
const networkCurrency_model_1 = require("../models/networkCurrency.model");
/**
 * Generation hash resolver
 */
class NetworkCurrencyResolver {
    /**
     * Resolves generationHash. If not provided by the user, this is asked to the node.
     * @param {CreateProfileOptions} options - Command options.
     * @throws {ExpectedError}
     * @returns {Promise<string>}
     */
    async resolve(options) {
        try {
            const { namespaceId, divisibility } = options;
            if (namespaceId && divisibility) {
                return networkCurrency_model_1.NetworkCurrency.createFromDTO({ namespaceId, divisibility });
            }
            const firstBlockTransactions = await new symbol_sdk_1.TransactionHttp(options.url)
                .search({ height: symbol_sdk_1.UInt64.fromUint(1), pageSize: 100, group: symbol_sdk_1.TransactionGroup.Confirmed })
                .toPromise();
            return networkCurrency_model_1.NetworkCurrency.createFromFirstBlockTransactions(firstBlockTransactions.data);
        }
        catch (ignored) {
            throw new clime_1.ExpectedError('The CLI cannot get the network currency mosaic description. Pass the network currency mosaic options with the options `namespace-id` and `divisibility`. E.g.: --namespace-id symbol.xym --divisibility 6');
        }
    }
}
exports.NetworkCurrencyResolver = NetworkCurrencyResolver;
