"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var helper_1 = require("../../../../helper");
var number_decoder_1 = require("./number-decoder");
var MultipleMaskConverter = /** @class */ (function () {
    // protected static _instance: UniqMaskDecoder;
    function MultipleMaskConverter(mapping) {
        this._mapping = mapping;
        // this._mapping[0x00] = (null as any as OutputType);
        // this._mapping[0x01] = (null as any as OutputType);
    }
    MultipleMaskConverter.prototype.decode = function (body) {
        return MultipleMaskConverter.decodeAll(body, this._mapping);
    };
    /**
     * TODO check that not use more than the first 7 bits
     * @param types
     */
    MultipleMaskConverter.prototype.encode = function (types) {
        return MultipleMaskConverter.encodeAll(types, this._mapping);
    };
    MultipleMaskConverter.encodeAll = function (values, mapping) {
        var _reverseMapping = helper_1.Helper.swapMap(mapping);
        var result = 0x0;
        for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
            var type = values_1[_i];
            if (type in _reverseMapping) {
                var mask = parseInt(_reverseMapping[type]);
                result = result | mask;
            }
        }
        return Uint8Array.from([result & 0xFF]);
    };
    MultipleMaskConverter.decodeAll = function (value, mapping) {
        var results = [];
        if (typeof value !== "number") {
            value = number_decoder_1.NumberConverter.fromOpaqueMsb(value, Math.min(value.length * 8, 32));
        }
        for (var key in mapping) {
            var mask = parseInt(key);
            if (mask == 0 && value == 0) {
                results.push(mapping[mask]);
            }
            else if ((mask & value) != 0) {
                results.push(mapping[mask]);
            }
        }
        return results;
    };
    return MultipleMaskConverter;
}());
exports.MultipleMaskConverter = MultipleMaskConverter;
