/*
 * Copyright (C) 2024-present Puter Technologies Inc.
 *
 * This file is part of Puter.
 *
 * Puter is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
export class AbstractContext {
    get constants () {
        return this.instance_.constants;
    }
    get consts () {
        return this.constants;
    }
    get variables () {
        return this.instance_.valuesAccessor;
    }
    get vars () {
        return this.variables;
    }
}

// export class SubContext extends AbstractContext {
//     constructor ({ parent, changes }) {
//         for ( const k in parent.spec )
//     }
// }

export class Context extends AbstractContext {
    constructor (spec) {
        super();
        this.spec = { ...spec };

        this.instance_ = {};

        if ( ! spec.constants ) spec.constants = {};

        const constants = {};
        for ( const k in this.spec.constants ) {
            Object.defineProperty(constants, k, {
                value: this.spec.constants[k],
                enumerable: true,
            });
        }
        this.instance_.constants = constants;

        // const values = {};
        // for ( const k in this.spec.variables ) {
        //     Object.defineProperty(values, k, {
        //         value: this.spec.variables[k],
        //         enumerable: true,
        //         writable: true
        //     });
        // }
        // this.instance_.values = values;
    }
}
