"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validObjectKeys = validObjectKeys;
exports.validateGraphSpec = validateGraphSpec;
exports.validateBundleSpec = validateBundleSpec;
exports.validateSpecs = validateSpecs;
exports.validateUnitBundleSpec = validateUnitBundleSpec;
exports.validateGraphUnitSpec = validateGraphUnitSpec;
const f_1 = require("../system/f/object/Keys/f");
const ALLOWED_BUNDLE_SPEC_KEY_SET = new Set(['spec', 'specs', 'metadata']);
const ALLOWED_UNIT_BUNDLE_SPEC_KEY_SET = new Set(['unit', 'specs', 'metadata']);
const ALLOWED_SPEC_KEY_SET = new Set([
    'name',
    'version',
    'id',
    'units',
    'merges',
    'data',
    'component',
    'metadata',
    'inputs',
    'outputs',
    'type',
    'render',
    'user',
]);
function validObjectKeys(obj, set) {
    let valid = true;
    const _keys = (0, f_1.keys)(obj);
    for (const key of _keys) {
        if (!set.has(key)) {
            valid = false;
            break;
        }
    }
    return valid;
}
function validateGraphSpec(spec) {
    return validObjectKeys(spec, ALLOWED_SPEC_KEY_SET);
}
function validateBundleSpec(bundle) {
    if (!validObjectKeys(bundle, ALLOWED_BUNDLE_SPEC_KEY_SET)) {
        return false;
    }
    const { spec = {}, specs = {}, metadata = {} } = bundle;
    if (!validateGraphSpec(spec)) {
        return false;
    }
    if (!validateSpecs(specs)) {
        return false;
    }
    return true;
}
function validateSpecs(specs) {
    for (const specId in specs) {
        if (!validateGraphSpec(specs[specId])) {
            return false;
        }
    }
    return true;
}
function validateUnitBundleSpec(bundle) {
    if (!validObjectKeys(bundle, ALLOWED_UNIT_BUNDLE_SPEC_KEY_SET)) {
        return false;
    }
    const { unit, specs } = bundle;
    if (!validateGraphUnitSpec(unit)) {
        return false;
    }
    if (!validateSpecs(specs)) {
        return false;
    }
    return true;
}
function validateGraphUnitSpec(unit) {
    // TODO
    return true;
}
//# sourceMappingURL=validate.js.map