"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FIFOQueue = exports.createFIFOQueue = void 0;
class FIFOQueue extends Array {
    constructor(_logger, handler = {}) {
        super();
        this.toSmallString = () => {
            let that = this;
            let res = "SmallStr";
            /*        for (let i = 0; i < that.size(); i++) {
                        let msg = that[i];
                        res+= msg.id + ", side : " + msg.side + ", isEvent : " + msg.isEvent + ", event : " + msg.event + ", deleted : " + msg.deleted + ", modified : " + msg.modified + ", content : " + msg.content + "\n";
                    }
                    // */
            return res;
        };
        this.queue = [];
        this.logger = _logger;
        //this.proxy = new Proxy(this, this.handler( p => p.queue,                              //target array
        this.proxy = new Proxy(this.queue, handler(_logger)); //target array
        /*this.proxy = new Proxy(this.queue, this.handler( p => p.queue,                              //target array
            p => p.x,                                   //getter
            (p, v) => p.x = v                           //setter
        )); // */
        return this.proxy;
    }
    // Ajoute un élément à la fin de la file d'attente
    enqueue(item) {
        //this.queue.push(item);
        // @ts-ignore
        this.push(item);
    }
    // Retire et retourne le premier élément de la file d'attente
    dequeue() {
        //return this.queue.shift();
        // @ts-ignore
        return this.shift();
    }
    // Retourne le premier élément de la file d'attente sans le retirer
    peek() {
        // @ts-ignore
        return this.length > 0 ? this[0] : undefined;
    }
    // Retourne vrai si la file d'attente est vide, faux sinon
    isEmpty() {
        // @ts-ignore
        return this.length === 0;
    }
    // Retourne la taille de la file d'attente
    size() {
        // @ts-ignore
        return this.length;
    }
    // Vide la file d'attente
    clear() {
        // @ts-ignore
        this.length = 0;
    }
    handler(container, getter, setter) {
        return {
        /*  get: (object, key) => {
             if (key==='length') {
                 return this.queue.length;
             } else if (typeof Array.prototype[key]=='function') { //array methods
                 if (typeof this[key]=='function') {
                     return this[key]();
                 } else {
                     return this.emulateArrayMethod(object, key, container, getter);
                 }
             } else {
                 try {                                               //access array by index
                     if (key===parseInt(key).toString()) {
                         if (0 <= key && key < this.queue.length) {
                             return this.queue[key];
                         } else {
                             throw "index out of bondary";
                         }
                     } else {
                         throw "float index";
                     }
                 } catch (err) {                                   //access to object by literal
                     return Reflect.get(object, key);
                 }
             }
         },

         set: (object, key, value) => {
             this.queue[key] = value;
             return true;
         }
         // */
        };
    }
    emulateArrayMethod(object, key, container, getter) {
        return (...args) => {
            try {
                console.log("Deprecated emulation. Better to define method " + key + "() by hands.");
                return;
                //return Reflect.apply([][key], container(object), args).map(x => getter(x));
            }
            catch (err) {
                throw "Array method can not be emulated!";
            }
        };
    }
}
exports.FIFOQueue = FIFOQueue;
/*
// Exemple d'utilisation
const fifoQueue = new FIFOQueue<number>();
fifoQueue.enqueue(1);
fifoQueue.enqueue(2);
fifoQueue.enqueue(3);

console.log(fifoQueue.dequeue()); // Output: 1
console.log(fifoQueue.size());    // Output: 2
console.log(fifoQueue.peek());    // Output: 2
console.log(fifoQueue.isEmpty()); // Output: false

fifoQueue.clear();
console.log(fifoQueue.isEmpty()); // Output: true
// */
// Static factories
let createFIFOQueue = function (_logger) {
    return new FIFOQueue(_logger);
};
exports.createFIFOQueue = createFIFOQueue;
module.exports.createFIFOQueue = createFIFOQueue;
module.exports.FIFOQueue = FIFOQueue;
//# sourceMappingURL=FIFOQueue.js.map