"use strict";
/* TODO auto-generated eslint ignore, please fix! */
/* eslint @typescript-eslint/no-inferrable-types: "off", no-var: "off" */
/**
 * Group of fields
 *
 *  Copyright (C) 2010-2019 R-T Specialty, LLC.
 *
 *  This file is part of liza.
 *
 *  liza is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Group = void 0;
/**
 * Group of fields
 */
var Group = /** @class */ (function () {
    function Group() {
        /**
         * Maximum number of rows permitted
         *
         * Must be 0 by default (not 1) to ensure we are unbounded by default.
         */
        this._maxRows = 0;
        /**
         * Minimum number of rows permitted
         */
        this._minRows = 1;
        /**
         * Whether the group is preventing from adding/removing rows
         */
        this._locked = false;
        /**
         * Stores names of fields available in the group (includes linked)
         */
        this._fields = [];
        /**
         * Stores names of fields available exclusively in the group (no linked)
         */
        this._exclusiveFields = [];
        /**
         * Hashed exclusive fields for quick lookup
         * @type {Object}
         */
        this._exclusiveHash = {};
        /**
         * Stores names of cmatch fields available exclusively in the group (no linked)
         */
        this._exclusiveCmatchFields = [];
        /**
         * Names of fields that are visible to the user
         *
         * For example: excludes external fields, but includes display.
         */
        this._userFields = [];
        /**
         * The id of the field that will determine the number of indexes in the
         * group
         */
        this._indexFieldName = '';
        /**
         * If the group should display internal fields
         */
        this._isInternal = false;
        /**
         * A list of when conditions for the group
         */
        this._when_field = '';
    }
    /**
     * Gets or sets the maximum numbers of rows that may appear in the group
     *
     * @param max - max maximum number of rows
     *
     * @return the man rows value
     */
    Group.prototype.maxRows = function (max) {
        if (max !== undefined) {
            this._maxRows = +max;
            return this._maxRows;
        }
        return this._maxRows;
    };
    /**
     * Gets or sets the minimum numbers of rows that may appear in the group
     *
     * @param min - minimum number of rows
     *
     * @return the min rows value
     */
    Group.prototype.minRows = function (min) {
        if (min !== undefined) {
            this._minRows = +min;
            return this._minRows;
        }
        return this._minRows;
    };
    /**
     * Gets or sets the locked status of a group
     *
     * When a group is locked, rows/groups cannot be removed
     *
     * @param locked - whether the group should be locked
     *
     * @return Group|Boolean self if setting, otherwise locked status
     */
    Group.prototype.locked = function (locked) {
        if (locked !== undefined) {
            this._locked = !!locked;
            return this;
        }
        return this._locked;
    };
    /**
     * Set names of fields available in the group
     *
     * @param fields - field names
     */
    Group.prototype.setFieldNames = function (fields) {
        // store copy of the fields to ensure that modifying the array that was
        // passed in does not modify our values
        this._fields = fields.slice(0);
        return this;
    };
    /**
     * Returns the group field names
     */
    Group.prototype.getFieldNames = function () {
        return this._fields;
    };
    /**
     * Set names of fields available in the group (no linked)
     *
     * @param fields - field names
     */
    Group.prototype.setExclusiveFieldNames = function (fields) {
        // store copy of the fields to ensure that modifying the array that was
        // passed in does not modify our values
        this._exclusiveFields = fields.slice(0);
        // hash 'em for quick lookup
        var i = fields.length;
        while (i--) {
            this._exclusiveHash[fields[i]] = true;
        }
        return this;
    };
    /**
     * Returns the group field names (no linked)
     */
    Group.prototype.getExclusiveFieldNames = function () {
        return this._exclusiveFields;
    };
    /**
     * Set names of cmatch fields available in the group (no linked)
     *
     * @param fields - field names
     */
    Group.prototype.setExclusiveCmatchFieldNames = function (fields) {
        this._exclusiveCmatchFields = fields.slice(0);
        return this;
    };
    /**
     * Returns the cmatch fields available in the group
     */
    Group.prototype.getExclusiveCmatchFieldNames = function () {
        return this._exclusiveCmatchFields;
    };
    Group.prototype.setUserFieldNames = function (fields) {
        this._userFields = fields.slice(0);
        return this;
    };
    Group.prototype.getUserFieldNames = function () {
        return this._userFields;
    };
    /**
     * Set flag to display internal fields
     *
     * @param internal - internal flag
     */
    Group.prototype.setInternal = function (internal) {
        this._isInternal = !!internal;
        return this;
    };
    /**
     * Get flag to display internal fields
     */
    Group.prototype.isInternal = function () {
        return this._isInternal;
    };
    /**
     * Returns whether the group contains the given field
     *
     * @param field - name of field
     *
     * @return true if exclusively contains field, otherwise false
     */
    Group.prototype.hasExclusiveField = function (field) {
        return !!this._exclusiveHash[field];
    };
    Group.prototype.setIndexFieldName = function (name) {
        this._indexFieldName = '' + name;
        return this;
    };
    Group.prototype.getIndexFieldName = function () {
        return this._indexFieldName;
    };
    /**
     * Sets the when field name
     *
     * @param when - the visibility classification for the group
     */
    Group.prototype.setWhenFieldName = function (when) {
        this._when_field = when;
        return this;
    };
    /**
     * Get the when field name
     *
     * @return the when field name
     */
    Group.prototype.getWhenFieldName = function () {
        return this._when_field;
    };
    return Group;
}());
exports.Group = Group;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiR3JvdXAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJHcm91cC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsb0RBQW9EO0FBQ3BELHlFQUF5RTtBQUN6RTs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQW1CRzs7O0FBSUg7O0dBRUc7QUFDSDtJQUFBO1FBQ0U7Ozs7V0FJRztRQUNLLGFBQVEsR0FBVyxDQUFDLENBQUM7UUFFN0I7O1dBRUc7UUFDSyxhQUFRLEdBQVcsQ0FBQyxDQUFDO1FBRTdCOztXQUVHO1FBQ0ssWUFBTyxHQUFZLEtBQUssQ0FBQztRQUVqQzs7V0FFRztRQUNLLFlBQU8sR0FBYSxFQUFFLENBQUM7UUFFL0I7O1dBRUc7UUFDSyxxQkFBZ0IsR0FBYSxFQUFFLENBQUM7UUFFeEM7OztXQUdHO1FBQ0ssbUJBQWMsR0FBUSxFQUFFLENBQUM7UUFFakM7O1dBRUc7UUFDSywyQkFBc0IsR0FBYSxFQUFFLENBQUM7UUFFOUM7Ozs7V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