"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.headlessModel = void 0;
const shell_1 = require("@things-factory/shell");
const process_1 = require("../service/process/process");
const headlessModel = async (target) => {
    var { domain, id, model } = target || {};
    if (model) {
        if (typeof model == 'string') {
            model = JSON.parse(model);
        }
        else if (typeof model !== 'object') {
            throw 'model should be a string or object';
        }
    }
    else if (id) {
        const repository = (0, shell_1.getRepository)(process_1.Process);
        var process = await repository.findOneBy({ domain: { id: domain.id }, id });
        model = JSON.parse(process.model);
    }
    else {
        throw 'parameter model or id mandatory';
    }
    return {
        base: (0, shell_1.getContextPath)(domain === null || domain === void 0 ? void 0 : domain.subdomain),
        model,
        process
    };
};
exports.headlessModel = headlessModel;
//# sourceMappingURL=headless-model.js.map