/**
 * Typed wrapper around the `user_preference` entity that the agent activation
 * flow uses to remember the operator's onboarding choices.
 *
 * `user_preference` is intentionally schema-less at the storage layer — Neotoma
 * infers its schema lazily the first time the entity is stored, and the shape
 * evolves as new preferences are added (data-type checklist, onboarding mode,
 * primary vertical, secondary verticals, …). This module exposes the canonical
 * field shape so callers across CLI, MCP, and HTTP surfaces don't reinvent it.
 *
 * Storage is deliberately delegated to whatever store path the caller already
 * has (e.g. `store_structured` over MCP, `neotoma store` from CLI) instead of
 * wiring this module directly into the SQLite or HTTP layer. That keeps the
 * wrapper portable and keeps unit tests pure-function.
 */
import { VERTICAL_PACKS } from "../verticals/registry.js";
/**
 * Returns true when `slug` is a known vertical (or the meta-fallback).
 * Defensive helper used before persisting a user_preference so we don't write
 * a typo that would break later registry lookups.
 */
export function isKnownVerticalSlug(slug) {
    return VERTICAL_PACKS.some((p) => p.slug === slug);
}
/**
 * Build a `user_preference` payload ready to hand to `store_structured`.
 * Throws when an unknown vertical slug is supplied so the agent fails fast at
 * the activation boundary instead of silently corrupting later detection runs.
 */
export function buildUserPreferenceUpsert(input) {
    if (input.primary_vertical && !isKnownVerticalSlug(input.primary_vertical)) {
        throw new Error(`Unknown vertical slug "${input.primary_vertical}"; expected one of: ${VERTICAL_PACKS.map((p) => p.slug).join(", ")}`);
    }
    if (input.secondary_verticals) {
        for (const slug of input.secondary_verticals) {
            if (!isKnownVerticalSlug(slug)) {
                throw new Error(`Unknown vertical slug "${slug}" in secondary_verticals`);
            }
        }
    }
    const record = {
        entity_type: "user_preference",
        identity_opt_out: "heuristic_canonical_name",
    };
    if (input.canonical_name)
        record.canonical_name = input.canonical_name;
    if (input.onboarding_mode)
        record.onboarding_mode = input.onboarding_mode;
    if (input.preference_categories?.length) {
        record.preference_categories = [...input.preference_categories];
    }
    if (input.primary_vertical)
        record.primary_vertical = input.primary_vertical;
    if (input.secondary_verticals?.length) {
        record.secondary_verticals = [...input.secondary_verticals];
    }
    if (input.vertical_detection) {
        record.vertical_detection = { ...input.vertical_detection };
    }
    if (input.notes)
        record.notes = input.notes;
    return record;
}
/**
 * Suggested schema extension applied via `update_schema_incremental` once the
 * user_preference entity has been auto-inferred. Exposed as data so an
 * activation runner (CLI/MCP) can apply it idempotently without duplicating
 * the field list.
 */
export const USER_PREFERENCE_SCHEMA_EXTENSION = {
    entity_type: "user_preference",
    fields_to_add: {
        primary_vertical: {
            type: "string",
            description: "Single canonical vertical (use case) for this operator's install. Slug from `src/services/verticals/registry.ts`.",
        },
        secondary_verticals: {
            type: "array",
            items: { type: "string" },
            description: "List of additional vertical slugs the operator works in alongside the primary one.",
        },
        vertical_detection: {
            type: "object",
            description: "Metadata about how primary_vertical was determined (filesystem signals, user-declared, ambiguity resolution).",
        },
        onboarding_mode: {
            type: "string",
            enum: ["quick_win", "guided", "power_user"],
            description: "Onboarding mode selected in Stage 1 of the activation flow.",
        },
        preference_categories: {
            type: "array",
            items: { type: "string" },
            description: "Data-type checkboxes ticked by the operator in Stage 1.",
        },
    },
};
//# sourceMappingURL=user_preference.js.map