/**
 * Legacy adapter — bridges existing registerSerializer() calls into the new
 * plugin host registry.
 *
 * Phase 0: when a serializer is registered, we synthesize a minimal
 * BackendModule manifest (type, table, label, slugFrom, serializer,
 * systemPrompt) and push it into pluginHost.registerBackendModule(). The
 * other slots (backend.{ migrations, services, mcpServer, routes }) stay
 * empty — existing wiring (createMcpServers, app.use(routes), migrate.ts)
 * still mounts those independently.
 *
 * The systemPrompt fragments below mirror the current hardcoded behavior in
 * src/server/services/chat-context.ts so Phase 2 (prompt builder refactor)
 * keeps byte-identical output.
 *
 * As each entity migrates to its own vertical slice in Phase 3, the matching
 * `LEGACY_MANIFEST_DEFAULTS` entry below is deleted and the per-entity
 * plugin.ts file becomes the source of truth.
 */
import { pluginHost } from './host.js';
/**
 * Hardcoded per-type defaults. Mirror current chat-context.ts behaviour:
 *   - endpoint, dto, database-table appear in the prompt today
 *   - ui-view is intentionally absent from the prompt (current behaviour);
 *     legacy adapter still registers a placeholder so plugin host knows the
 *     module exists, but Phase 2 prompt builder will skip plugins whose
 *     `systemPrompt.roleNoun` is empty (= opt-out).
 */
const LEGACY_MANIFEST_DEFAULTS = {
// All four built-in entity types have been migrated to vertical slice plugins
// under src/server/entities/{type}/plugin.ts. Legacy adapter remains as a
// safety net for ad-hoc registerSerializer() callers; empty defaults map.
};
const trivialSlugFrom = (_data) => {
    throw new Error('plugin-host legacy adapter: slugFrom not implemented for this module yet (Phase 3 will wire it)');
};
/**
 * Called by serialization/registry.ts whenever a serializer registers itself.
 * If a manifest for this type already exists in the host, the serializer slot
 * is updated in-place. Otherwise, a synthetic BackendModule is built from
 * LEGACY_MANIFEST_DEFAULTS and pushed into the host.
 *
 * `section` is intentionally NOT registered as a plugin — sections are a
 * non-entity construct (M06). Their serializer stays in the legacy
 * SerializerRegistry path only.
 */
export function legacyRegisterServerSerializer(serializer) {
    if (serializer.type === 'section')
        return; // sections are not entities
    // If a vertical slice plugin already registered this type, do not overwrite
    // with the legacy synthesized manifest.
    if (pluginHost.getAvailable(serializer.type))
        return;
    const defaults = LEGACY_MANIFEST_DEFAULTS[serializer.type];
    if (!defaults) {
        // Unknown legacy type — register with stub defaults. Allows future plugins
        // to ride this code path before they have a vertical slice.
        pluginHost.registerBackendModule({
            type: serializer.type,
            table: serializer.type.replace(/-/g, '_'),
            label: serializer.type,
            labelPlural: `${serializer.type}s`,
            displayOrder: 999,
            pathPrefix: `/${serializer.type}s`,
            slugFrom: trivialSlugFrom,
            serializer,
            systemPrompt: {
                roleNoun: '',
                countStat: { placeholder: '', sqlQuery: '', label: '' },
                mcpToolsLine: '',
            },
        });
        return;
    }
    const module = {
        type: serializer.type,
        table: defaults.table,
        label: defaults.label,
        labelPlural: defaults.labelPlural,
        pathPrefix: `/${serializer.type}s`,
        displayOrder: defaults.displayOrder,
        slugFrom: trivialSlugFrom,
        serializer,
        systemPrompt: defaults.systemPrompt,
    };
    pluginHost.registerBackendModule(module);
}
//# sourceMappingURL=legacy-adapter.js.map