"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DialogFactory = void 0;
const dialog_1 = require("./dialog");
const dialog_global_registry_1 = require("./dialog-global-registry");
const id_1 = require("./utils/id");
/**
 * Factory for creating Dialog instances.
 * Abstracts the creation of MainDialog and SideDialog with proper type hierarchy.
 */
class DialogFactory {
    /**
     * Create a new MainDialog instance.
     */
    static createMainDialog(dlgStore, taskDocPath, agentId, id, initialState) {
        const mainDialog = new dialog_1.MainDialog(dlgStore, taskDocPath, id, agentId, initialState);
        dialog_global_registry_1.globalDialogRegistry.register(mainDialog);
        return mainDialog;
    }
    /**
     * Create a new SideDialog instance.
     */
    static createSideDialog(askerDialog, taskDocPath, targetAgentId, mentionList, tellaskContent, options, initialState) {
        const generatedId = (0, id_1.generateDialogID)();
        const mainDialog = askerDialog instanceof dialog_1.MainDialog
            ? askerDialog
            : askerDialog instanceof dialog_1.SideDialog
                ? askerDialog.mainDialog
                : (() => {
                    throw new Error(`createSideDialog invariant violation: unsupported asker type (${askerDialog.constructor.name})`);
                })();
        const sideDialogId = new dialog_1.DialogID(generatedId, mainDialog.id.rootId);
        return new dialog_1.SideDialog(askerDialog.dlgStore, mainDialog, taskDocPath, sideDialogId, targetAgentId, (0, dialog_1.buildSideDialogAskerStack)({
            askerDialogId: options.askerDialogId,
            assignment: {
                callName: options.callName,
                mentionList,
                tellaskContent,
                originMemberId: options.originMemberId,
                askerDialogId: options.askerDialogId,
                callId: options.callId,
                callSiteCourse: options.callSiteCourse,
                callSiteGenseq: options.callSiteGenseq,
                collectiveTargets: options.collectiveTargets,
                effectiveFbrEffort: options.effectiveFbrEffort,
            },
        }), options.sessionSlug, initialState);
    }
    /**
     * Check if a dialog is a MainDialog.
     */
    static isMainDialog(dialog) {
        return dialog instanceof dialog_1.MainDialog;
    }
    /**
     * Check if a dialog is a SideDialog.
     */
    static isSideDialog(dialog) {
        return dialog instanceof dialog_1.SideDialog;
    }
}
exports.DialogFactory = DialogFactory;
