"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityEditor = void 0;
const HubContent_1 = require("../content/HubContent");
const HubDiscussion_1 = require("../discussions/HubDiscussion");
const HubGroup_1 = require("../groups/HubGroup");
const HubInitiative_1 = require("../initiatives/HubInitiative");
const HubPage_1 = require("../pages/HubPage");
const HubProject_1 = require("../projects/HubProject");
const HubSite_1 = require("../sites/HubSite");
const getTypeFromEntity_1 = require("./getTypeFromEntity");
const HubEvent_1 = require("../events/HubEvent");
const HubUser_1 = require("../users/HubUser");
const HubChannel_1 = require("../channels/HubChannel");
const HubInitiativeTemplate_1 = require("../initiative-templates/HubInitiativeTemplate");
const HubTemplate_1 = require("../templates/HubTemplate");
class EntityEditor {
    constructor(instance) {
        this.instance = instance;
    }
    static fromEntity(entity, context) {
        const entityType = (0, getTypeFromEntity_1.getTypeFromEntity)(entity);
        // Create the instance and cast to EntityEditor
        let editor;
        if (entityType === "project") {
            editor = HubProject_1.HubProject.fromJson(entity, context);
        }
        if (entityType === "initiative") {
            editor = HubInitiative_1.HubInitiative.fromJson(entity, context);
        }
        if (entityType === "content") {
            editor = HubContent_1.HubContent.fromJson(entity, context);
        }
        if (entityType === "site") {
            editor = HubSite_1.HubSite.fromJson(entity, context);
        }
        if (entityType === "page") {
            editor = HubPage_1.HubPage.fromJson(entity, context);
        }
        if (entityType === "discussion") {
            editor = HubDiscussion_1.HubDiscussion.fromJson(entity, context);
        }
        if (entityType === "template") {
            editor = HubTemplate_1.HubTemplate.fromJson(entity, context);
        }
        if (entityType === "channel") {
            editor = HubChannel_1.HubChannel.fromJson(entity, context);
        }
        if (entityType === "event") {
            editor = HubEvent_1.HubEvent.fromJson(entity, context);
        }
        if (entityType === "group") {
            editor = HubGroup_1.HubGroup.fromJson(entity, context);
        }
        if (entityType === "initiativeTemplate") {
            editor = HubInitiativeTemplate_1.HubInitiativeTemplate.fromJson(entity, context);
        }
        if (entityType === "user") {
            editor = HubUser_1.HubUser.fromJson(entity, context);
        }
        if (editor) {
            return new EntityEditor(editor);
        }
        else {
            throw new Error(`Unsupported entity type: ${entity.type}`);
        }
    }
    async getConfig(i18nScope, type) {
        return this.instance.getEditorConfig(i18nScope, type);
    }
    toEditor(editorContext = {}, include = []) {
        // This is ugly but it's the only way to get the type to be correct
        return this.instance.toEditor(editorContext, include);
    }
    async save(editor, editorContext) {
        return this.instance.fromEditor(editor, editorContext);
    }
}
exports.EntityEditor = EntityEditor;
//# sourceMappingURL=EntityEditor.js.map