import { IMPOSSIBLE, VersionInfo } from '@start9labs/start-sdk'

/**
 * v1.1.0:2 — model-agnostic AI program generation.
 *
 * Five providers behind one streaming abstraction:
 *
 *   - claude              (Anthropic)
 *   - openai              (api.openai.com)
 *   - openai-compatible   (any base URL — OpenRouter / LiteLLM /
 *                          vLLM / Together / your own gateway)
 *   - gemini              (Google)
 *   - ollama              (self-hosted; no key; uses LAN URL)
 *
 * The "self-hosted Ollama on Start9" angle is the killer use case —
 * point Settings → AI integration → Base URL at
 * `http://ollama.embassy:11434` (or whatever Ollama service you have
 * on the same StartOS host) and no API keys ever leave your network.
 *
 * Workflow
 *   1. Settings → AI integration: pick provider + model + key/URL.
 *   2. AI → Generate program: pick a template, type your specifics
 *      ("8 weeks heavy leg emphasis"), click Generate.
 *   3. Watch the response stream in word-by-word via SSE.
 *   4. Server validates the JSON output against a Zod schema and
 *      stores both raw + parsed in AIGeneration.
 *   5. Preview UI shows the program tree. Unknown exercises (the
 *      model picked something not in your library) are highlighted
 *      and you can map them to existing entries or remove them.
 *   6. Apply → materializes into a real Program (same schema/UI as
 *      the v1.1.0:1 manual programs).
 *
 * Ships with 5 built-in prompt templates (hypertrophy block,
 * strength block, endurance/running block, recovery week, custom).
 * Built-ins reconcile per-boot the same way curated exercises do.
 * Both admin and regular users can create their own templates.
 *
 * Schema additions
 *   - UserPreferences: aiProvider, aiModel, aiBaseUrl, aiApiKey
 *     (plaintext — consistent with the rest of /data/app.db; the
 *     host-level threat model assumes the operator owns /data).
 *   - AIPromptTemplate (built-ins userId=NULL, user templates
 *     userId=<them>).
 *   - AIGeneration (one row per generate request; raw response,
 *     parsed program, status, applied program id, token counts).
 *
 * Backward compatible: existing UserPreferences rows get the new
 * columns added with NULL defaults (compat ALTER on first boot);
 * the dead enableClaudeAI / claudeApiKey columns from v1.0.0:1-7
 * stay as no-op fields.
 */
export const v_1_1_0_2 = VersionInfo.of({
  version: '1.1.0:2',
  releaseNotes: {
    en_US:
      'AI program generation. Pick from Claude / OpenAI / Gemini / OpenAI-compatible / self-hosted Ollama. Settings → AI integration to configure (Ollama on Start9 needs no API key). AI → Generate program to pick a template, describe what you want, watch the response stream in, review the parsed program, and apply it to your Programs library. Ships 5 starter templates; both admin and regular users can create their own. Generation history is kept until you delete it (per-row Trash; admin-only "clear all" via /api/admin/ai/generations).',
  },
  migrations: {
    up: async () => {},
    down: IMPOSSIBLE,
  },
})
