// SPDX-License-Identifier: Apache-2.0
export class MutableFacadeArray {
    facadeObjectConstructor;
    encapsulatedObjectConstructor;
    encapsulatedArray;
    facadeArray;
    constructor(facadeObjectConstructor, encapsulatedObjectConstructor, encapsulatedArray) {
        this.facadeObjectConstructor = facadeObjectConstructor;
        this.encapsulatedObjectConstructor = encapsulatedObjectConstructor;
        this.encapsulatedArray = encapsulatedArray;
        this.facadeArray = [];
        for (const encapsulatedObject of encapsulatedArray) {
            const facadeObject = new this.facadeObjectConstructor(encapsulatedObject);
            this.facadeArray.push(facadeObject);
        }
    }
    get length() {
        return this.facadeArray.length;
    }
    add(value) {
        const encapsulatedObject = value.encapsulatedObject;
        this.facadeArray.push(value);
        this.encapsulatedArray.push(encapsulatedObject);
    }
    addNew() {
        const encapsulatedObject = new this.encapsulatedObjectConstructor();
        const facadeObject = new this.facadeObjectConstructor(encapsulatedObject);
        this.add(facadeObject);
        return facadeObject;
    }
    addAll(...values) {
        for (const value of values) {
            this.add(value);
        }
    }
    get(index) {
        return this.facadeArray[index];
    }
    set(index, value) {
        this.facadeArray[index] = value;
        this.encapsulatedArray[index] = value.encapsulatedObject;
    }
    indexOf(value) {
        return this.facadeArray.indexOf(value);
    }
    find(predicate) {
        return this.facadeArray.find((element) => predicate(element));
    }
    includes(value) {
        return this.facadeArray.includes(value);
    }
    some(predicate) {
        return this.facadeArray.some((element) => predicate(element));
    }
    map(callback) {
        return this.facadeArray.map((element) => callback(element));
    }
    remove(value) {
        const facadeIndex = this.facadeArray.indexOf(value);
        if (facadeIndex !== -1) {
            this.facadeArray.splice(facadeIndex, 1);
        }
        const encapsulatedIndex = this.encapsulatedArray.indexOf(value.encapsulatedObject);
        if (encapsulatedIndex !== -1) {
            this.encapsulatedArray.splice(encapsulatedIndex, 1);
        }
    }
    clear() {
        this.facadeArray.splice(0);
        this.encapsulatedArray.splice(0);
    }
    *[Symbol.iterator]() {
        for (const element of this.facadeArray) {
            yield element;
        }
    }
}
//# sourceMappingURL=mutable-facade-array.js.map