"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.ResolutionStatementViews = void 0;
const symbol_sdk_1 = require("symbol-sdk");
const recipients_view_1 = require("../recipients.view");
const abstractStatementView_view_1 = require("./abstractStatementView.view");
class ResolutionStatementViews extends abstractStatementView_view_1.AbstractStatementView {
    constructor(statements) {
        super();
        this.statements = statements;
    }
    /**
     * Renders cell records
     * @returns {CellRecord[]}
     */
    render() {
        if (!this.statements.length) {
            return null;
        }
        const statementTypeLabel = symbol_sdk_1.ResolutionType[this.statements[0].resolutionType];
        return this.statements.map(({ height, unresolved, resolutionEntries }, index, self) => [
            this.getSectionTitle(`${statementTypeLabel} statement ${index + 1} of ${self.length}`),
            { Height: height.compact() },
            { Unresolved: this.getUnresolved(unresolved) },
            ...this.renderResolutionEntries(resolutionEntries),
        ]);
    }
    /**
     * Renders resolution entries
     * @private
     * @param {ResolutionEntry[]} entries
     * @returns {CellRecord[]}
     */
    renderResolutionEntries(entries) {
        return entries
            .map((entry, index, self) => this.renderResolutionEntry(entry, index, self.length))
            .reduce((acc, entry) => [...acc, ...entry], []);
    }
    /**
     * Renders resolution a entry
     * @private
     * @param {ResolutionEntry} entry
     * @param {number} index
     * @param {number} numberOfReceipts
     * @returns {CellRecord[]}
     */
    renderResolutionEntry(entry, index, numberOfReceipts) {
        return [
            this.getSectionTitle(`Resolution ${index + 1} of ${numberOfReceipts}`),
            { Resolved: this.getUnresolved(entry.resolved) },
            { Source: `Primary Id: ${entry.source.primaryId}, Secondary Id: ${entry.source.secondaryId}` },
        ];
    }
    getUnresolved(entry) {
        if (entry instanceof symbol_sdk_1.MosaicId) {
            return entry.toHex();
        }
        return recipients_view_1.RecipientsView.get(entry);
    }
}
exports.ResolutionStatementViews = ResolutionStatementViews;
