"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CosignatureResolver = void 0;
const symbol_sdk_1 = require("symbol-sdk");
const options_resolver_1 = require("../options-resolver");
/**
 * Cosignature resolver
 */
class CosignatureResolver {
    /**
     * Resolves an cosignature json array provided by the user.
     * @param {Options} options - Command options.
     * @param {string} altText - Alternative text.
     * @param {string} altKey - Alternative key.
     * @returns {Promise<CosignatureSignedTransaction[] | null>}
     */
    async resolve(options, altText, altKey) {
        const resolution = await (0, options_resolver_1.OptionsResolver)(options, altKey ? altKey : 'cosignatures', () => undefined, altText ? altText : 'Cosignature JSON array in square brackets (Enter to skip):', 'text', undefined);
        if (!resolution) {
            return null;
        }
        try {
            const cosignaturesParsed = JSON.parse(resolution);
            const cosignatures = cosignaturesParsed.map((p) => new symbol_sdk_1.CosignatureSignedTransaction(p.parentHash, p.signature, p.signerPublicKey, new symbol_sdk_1.UInt64([p.version.higher, p.version.lower])));
            return cosignatures;
        }
        catch (err) {
            console.log('Unexpected format! Please make sure the input is a valid JSON array. It must be wrapped in square brackets [].');
            process.exit();
        }
    }
}
exports.CosignatureResolver = CosignatureResolver;
