"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.AccountMosaicRestrictionView = void 0;
const symbol_sdk_1 = require("symbol-sdk");
const mosaics_view_1 = require("../../../mosaics.view");
class AccountMosaicRestrictionView {
    /**
     * Creates an instance of AccountMosaicRestrictionView.
     * @param {AccountMosaicRestrictionTransaction} tx
     */
    constructor(tx) {
        this.tx = tx;
    }
    /**
     * @static
     * @param {AccountMosaicRestrictionTransaction} tx
     * @returns {CellRecord}
     */
    static get(tx) {
        return new AccountMosaicRestrictionView(tx).render();
    }
    /**
     * @private
     * @returns {CellRecord}
     */
    render() {
        return {
            'Account restriction flag': symbol_sdk_1.MosaicRestrictionFlag[this.tx.restrictionFlags],
            ...this.getRestrictions(),
        };
    }
    /**
     * @private
     * @returns {CellRecord}
     */
    getRestrictions() {
        const numberOfAdditions = this.tx.restrictionAdditions.length;
        const numberOfDeletions = this.tx.restrictionDeletions.length;
        return {
            ...this.tx.restrictionAdditions.reduce((acc, mosaic, index) => ({
                ...acc,
                ...this.renderRestriction(mosaic, index, numberOfAdditions, 'Addition'),
            }), {}),
            ...this.tx.restrictionDeletions.reduce((acc, mosaic, index) => ({
                ...acc,
                ...this.renderRestriction(mosaic, index, numberOfDeletions, 'Deletion'),
            }), {}),
        };
    }
    /**
     * @private
     * @param {(MosaicId | NamespaceId)} mosaicId
     * @param {number} index
     * @param {number} numberOfRestrictions
     * @param {('Addition' | 'Deletion')} additionOrDeletion
     * @returns {CellRecord}
     */
    renderRestriction(mosaicId, index, numberOfRestrictions, additionOrDeletion) {
        const key = `${additionOrDeletion} ${index + 1} of ${numberOfRestrictions}`;
        return { [key]: mosaics_view_1.MosaicsView.getMosaicLabel(mosaicId) };
    }
}
exports.AccountMosaicRestrictionView = AccountMosaicRestrictionView;
