"use strict";

import {FormatModule} from "../FormatModule.ecma.js";

/**
 * @typedef {import("../FormatModule.ecma.js").FormatModule} FormatModule
 */

/**
 * @class UniquesFormat
 * @constructor
 * @param {!FormatModule} format 
 * @returns {void}
 * @access public
 * @static
 */
export const UniquesFormat = (function(){

    /**
     * @constructs UniquesFormat
    * @param {!FormatModule} format 
     * @returns {void}
     * @access private
     * @static
     */
    const UniquesFormat = function(format){

        /** @type {UniquesFormat} */
        const self = this;

        /**
         * @returns {void}
         * @access private
         */
        const constructor = () => {
            ["u", "unique", "uniques"].forEach(key => {
                format.modes[key] = self.get;
                format.checks[key] = self.check;
            });
        };

        /**
         * @param {[number, number]} coordenates 
         * @param {!(string|Array.<any|null>)} inputs 
         * @param {!Object.<string, any|null>} [shared = {}] 
         * @param {!Array.<string>} [fragments = []] 
         * @returns {string}
         * @access public
         */
        this.get = ([i, j], inputs, shared = {}, fragments = []) => {
            return format.execute([i, j], inputs, {
                ...(shared || {}), 
                /** @type {Array.<string>} */
                uniques_cache : []
            }, fragments);
        };

        /**
         * @param {[number, number]} coordenates 
         * @param {!string} string 
         * @param {!(string|Array.<string>)} inputs 
         * @param {!Object.<string, any|null>} [shared = {}] 
         * @param {!Array.<string>} [fragments = []] 
         * @returns {number}
         * @access public
         */
        this.check = ([i, j], string, inputs, shared = {}, fragments = []) => (
            format.get_check_length([i, j], string, [inputs], shared, fragments, false)
        );

        constructor();

    };

    return UniquesFormat;
})();