import { HubContent } from "../content/HubContent";
import { HubDiscussion } from "../discussions/HubDiscussion";
import { HubGroup } from "../groups/HubGroup";
import { HubInitiative } from "../initiatives/HubInitiative";
import { HubPage } from "../pages/HubPage";
import { HubProject } from "../projects/HubProject";
import { HubSite } from "../sites/HubSite";
import { getTypeFromEntity } from "./getTypeFromEntity";
import { HubEvent } from "../events/HubEvent";
import { HubUser } from "../users/HubUser";
import { HubChannel } from "../channels/HubChannel";
import { HubInitiativeTemplate } from "../initiative-templates/HubInitiativeTemplate";
import { HubTemplate } from "../templates/HubTemplate";
export class EntityEditor {
    constructor(instance) {
        this.instance = instance;
    }
    static fromEntity(entity, context) {
        const entityType = getTypeFromEntity(entity);
        // Create the instance and cast to EntityEditor
        let editor;
        if (entityType === "project") {
            editor = HubProject.fromJson(entity, context);
        }
        if (entityType === "initiative") {
            editor = HubInitiative.fromJson(entity, context);
        }
        if (entityType === "content") {
            editor = HubContent.fromJson(entity, context);
        }
        if (entityType === "site") {
            editor = HubSite.fromJson(entity, context);
        }
        if (entityType === "page") {
            editor = HubPage.fromJson(entity, context);
        }
        if (entityType === "discussion") {
            editor = HubDiscussion.fromJson(entity, context);
        }
        if (entityType === "template") {
            editor = HubTemplate.fromJson(entity, context);
        }
        if (entityType === "channel") {
            editor = HubChannel.fromJson(entity, context);
        }
        if (entityType === "event") {
            editor = HubEvent.fromJson(entity, context);
        }
        if (entityType === "group") {
            editor = HubGroup.fromJson(entity, context);
        }
        if (entityType === "initiativeTemplate") {
            editor = HubInitiativeTemplate.fromJson(entity, context);
        }
        if (entityType === "user") {
            editor = 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);
    }
}
//# sourceMappingURL=EntityEditor.js.map