"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require("../../../../Class/$");
const Functional_1 = require("../../../../Class/Functional");
const CodePathNotImplemented_1 = require("../../../../exception/CodePathNotImplemented");
const MethodNotImplementedError_1 = require("../../../../exception/MethodNotImplementedError");
const object_1 = require("../../../../util/object");
const _ids_1 = require("../../../_ids");
const f_1 = require("../../object/Keys/f");
class Spec_ extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['unit'],
            o: ['spec'],
        }, {
            input: {
                unit: {
                    ref: true,
                },
            },
            output: {
                spec: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_SPEC_0);
        this.__ = ['J'];
    }
    f({ unit }, done) {
        const spec = new (class Object_ extends _1.$ {
            get(name) {
                const _spec = unit.getSpec();
                return Promise.resolve(_spec[name]);
            }
            set(name, data) {
                const _spec = unit.getSpec();
                _spec[name] = data;
                return;
            }
            delete(name) {
                const _spec = unit.getSpec();
                delete _spec[name];
                return;
            }
            async hasKey(name) {
                const _spec = unit.getSpec();
                const has = (0, object_1.hasKey)(_spec, name);
                return has;
            }
            async keys() {
                const _spec = unit.getSpec();
                return (0, f_1.keys)(_spec);
            }
            deepGet(path) {
                const _spec = unit.getSpec();
                return (0, object_1.deepGet)(_spec, path);
            }
            deepSet(path, data) {
                const _spec = unit.getSpec();
                if (path[0] === 'metadata') {
                    const [_, ...rest] = path;
                    unit.setMetadata(rest, data);
                }
                else {
                    throw new CodePathNotImplemented_1.CodePathNotImplementedError();
                }
                return;
            }
            deepDelete(path) {
                throw new MethodNotImplementedError_1.MethodNotImplementedError();
            }
            subscribe(path, key, listener) {
                throw new MethodNotImplementedError_1.MethodNotImplementedError();
            }
        })(this.__system);
        done({
            spec,
        });
    }
}
exports.default = Spec_;
//# sourceMappingURL=index.js.map