import type { Column, ReferenceType } from '../types.js';

/**
 * Canonical card definitions — the single source of truth for card *content*
 * (title, description, details, category, files, notes).
 *
 * On startup `seed()` upserts these into SQLite. The `status` (column) is only
 * applied when a card is first created; afterwards the user's moves are
 * preserved across reseeds. User-entered comments, tags, and references live
 * entirely in the database.
 *
 * `references` link each card to the design doc pages that specify it — turning
 * the board into a bridge between implementation status and design.
 */
export interface SeedReference {
  label: string;
  type: ReferenceType;
  href: string;
}

export interface SeedCard {
  id: string;
  title: string;
  description: string;
  details: string;
  category: string;
  files: string | null;
  notes: string | null;
  status: Column;
  sortOrder: number;
  references: SeedReference[];
}

/** Helper for a doc-page reference. */
function doc(path: string, label: string): SeedReference {
  return { label, type: 'doc', href: path };
}

const N = (s: string | null) => s;

export const CARDS: SeedCard[] = [
  // ── DONE ──────────────────────────────────────────────────────────────────
  {
    id: 'G1',
    title: 'Galaxy Generation & Viewer',
    description: 'Complete procedural spiral galaxy with core cluster, disk layers, and beam structures. Interactive 3D viewer with star selection, parameter controls, and system connections.',
    details: 'Fully functional: generates star systems with faction distribution, nearest-neighbor connections, and POI contents. Control panel allows real-time parameter adjustment.',
    category: 'Onboarding',
    files: 'apps/game/src/gameplay/galaxy/mod.rs, apps/game/src/gameplay/galaxy/contents.rs',
    notes: N(null),
    status: 'done',
    sortOrder: 10,
    references: [doc('/docs/overview', 'Overview'), doc('/docs/backend', 'Backend Model')],
  },
  {
    id: 'G2',
    title: 'Character Creation',
    description: 'Bannerlord-style character generation with name selection, 4 origin archetypes, 3 ship choices, and 5-step backstory questionnaire with stat bonuses.',
    details: 'Fully functional: complete UI with scrollable panels, stat calculation display, and character draft persistence for campaign.',
    category: 'Onboarding',
    files: 'apps/game/src/gameplay/character_creation/mod.rs',
    notes: N(null),
    status: 'done',
    sortOrder: 11,
    references: [doc('/docs/gameplay', 'Gameplay Loop'), doc('/docs/overview', 'Overview')],
  },
  {
    id: 'G3',
    title: 'Starting Base Selection',
    description: 'System selection from outer-galaxy candidates with 3D visualization, POI display, and interactive camera controls.',
    details: 'Fully functional: shows candidate systems from generated galaxy, with camera focus on selection and system contents preview.',
    category: 'Onboarding',
    files: 'apps/game/src/gameplay/starting_base/mod.rs',
    notes: N(null),
    status: 'done',
    sortOrder: 12,
    references: [doc('/docs/gameplay', 'Gameplay Loop')],
  },
  {
    id: 'S1',
    title: 'Game State Management',
    description: 'AppState with clean transitions: MainMenu, Galaxy, CharacterCreation, StartingBaseSelection, InGame, Options.',
    details: 'Fully functional: state system works properly with OnEnter/OnExit/Update schedules for each game phase.',
    category: 'Core',
    files: 'apps/game/src/state.rs',
    notes: N(null),
    status: 'done',
    sortOrder: 20,
    references: [doc('/docs/architecture', 'Architecture')],
  },
  {
    id: 'S2',
    title: 'Campaign Persistence',
    description: 'Galaxy draft, character draft, and starting base selection persisted through game flow.',
    details: 'Fully functional: Resources carry data through state transitions. New game properly clears previous state.',
    category: 'Core',
    files: 'apps/game/src/gameplay/campaign.rs',
    notes: N(null),
    status: 'done',
    sortOrder: 21,
    references: [doc('/docs/architecture', 'Architecture'), doc('/docs/backend', 'Backend Model')],
  },
  {
    id: 'C1',
    title: 'Camera System',
    description: 'Three camera modes: Orbit (for galaxy inspection), Follow (for flight), Cinematic (for docked views).',
    details: 'Fully functional: orbit camera with mouse controls, camera transitions between modes, proper target following.',
    category: 'Core',
    files: 'apps/game/src/camera.rs',
    notes: N(null),
    status: 'done',
    sortOrder: 22,
    references: [doc('/docs/gameplay', 'Gameplay Loop')],
  },
  {
    id: 'P1',
    title: 'POI Data Structures',
    description: 'Complete POI type system: 7 planet types, asteroid belts, stations, stargates, anomalies, gas clouds.',
    details: 'Fully functional: POI generation with orbital mechanics, faction-based biasing, and system context awareness.',
    category: 'Content',
    files: 'apps/game/src/gameplay/galaxy/poi.rs, apps/game/src/gameplay/galaxy/contents.rs',
    notes: N(null),
    status: 'done',
    sortOrder: 30,
    references: [doc('/docs/gameplay', 'Gameplay Loop'), doc('/docs/backend', 'Backend Model')],
  },

  // ── IN PROGRESS ───────────────────────────────────────────────────────────
  {
    id: 'I1',
    title: 'In-System Scene Framework',
    description: 'Scene setup with star, POIs, and player ship. Docked/Flight state management exists.',
    details: 'Framework exists: scene spawns correctly, state transitions work. But UI is commented out and most gameplay features are stubs.',
    category: 'In-System',
    files: 'apps/game/src/gameplay/in_system/mod.rs, apps/game/src/gameplay/in_system/scene.rs',
    notes: 'UI systems removed/commented. No flight HUD visible to player.',
    status: 'in-progress',
    sortOrder: 110,
    references: [doc('/docs/gameplay', 'Gameplay Loop'), doc('/docs/architecture', 'Architecture')],
  },
  {
    id: 'I2',
    title: 'Target Selection',
    description: 'Click-to-select POIs (stations, asteroid belts) with selection tracking.',
    details: 'Framework exists: target selection works, but no gameplay uses the target yet. No distance display or spatial grouping.',
    category: 'In-System',
    files: 'apps/game/src/gameplay/in_system/target.rs',
    notes: 'Selection system works but no gameplay features depend on it yet.',
    status: 'in-progress',
    sortOrder: 111,
    references: [doc('/docs/gameplay', 'Gameplay Loop')],
  },
  {
    id: 'I3',
    title: 'Operations Framework',
    description: 'Timed operations system with undock (3s), travel (5s). Framework for docking (4s) and mining (8s).',
    details: 'Partial: undock and travel work. Docking and mining are skeleton operations marked TODO. No actual gameplay consequences.',
    category: 'In-System',
    files: 'apps/game/src/gameplay/in_system/operations.rs, apps/game/src/gameplay/in_system/flight.rs',
    notes: 'Only undock and approach are implemented. Docking and mining are TODO.',
    status: 'in-progress',
    sortOrder: 112,
    references: [doc('/docs/gameplay', 'Gameplay Loop'), doc('/docs/economy', 'Economy & Industry')],
  },
  {
    id: 'M1',
    title: 'Basic Movement',
    description: 'Click-to-move navigation with kinematic steering and velocity integration.',
    details: 'Partial: ship uses click-to-move + kinematic steering + velocity integration. Celestial-body orbital motion exists (movement/orbit.rs: Orbit component + update_orbits, registered in MovementPlugin). Ship flight itself is still kinematic — no physics thrust, no mass/inertia, no collision avoidance.',
    category: 'In-System',
    files: 'apps/game/src/gameplay/movement/{mod,kinematic,orbit,input,components}.rs',
    notes: 'Orbit component drives POIs/celestial bodies, not ship flight. AI ships reuse MoveTarget for navigation.',
    status: 'in-progress',
    sortOrder: 120,
    references: [doc('/docs/gameplay', 'Gameplay Loop'), doc('/docs/architecture', 'Architecture')],
  },
  {
    id: 'U1',
    title: 'Basic UI Shell',
    description: 'Main menu, galaxy control panel, info panels. Foundation for UI exists.',
    details: 'Partial: main menu and galaxy UI work. In-game flight UI is commented out. No station mode panel swap.',
    category: 'UI',
    files: 'apps/game/src/ui/',
    notes: 'Flight HUD and station UI are removed/commented in code.',
    status: 'in-progress',
    sortOrder: 130,
    references: [doc('/docs/overview', 'Overview')],
  },
  {
    id: 'I5',
    title: 'Contextual Action Panel',
    description: 'State-aware action buttons (Undock, Approach, Dock, Start Mining, Market, Fitting, Engage) shown bottom-right during InGame.',
    details: 'Built: ContextualActionPlugin registered in InSystemPlugin. Buttons are spawned/refreshed from game state (docked vs. flight, selected TargetKind) and fire ActionTriggeredEvent. Undock + Approach are wired to timed operations.',
    category: 'In-System',
    files: 'apps/game/src/gameplay/in_system/actions.rs',
    notes: 'Dock and StartMining handlers are TODO stubs; OpenMarket/OpenFitting trigger nothing yet (await those systems).',
    status: 'in-progress',
    sortOrder: 113,
    references: [doc('/docs/gameplay', 'Gameplay Loop')],
  },
  {
    id: 'N1',
    title: 'NPC Ships & AI',
    description: 'NPC spawning by system security & faction, state-machine behaviour (Idle/Patrol/Combat/Flee/Mining/Trading), perception, navigation, faction profiles.',
    details: 'Built & registered: AiPlugin runs on enter InGame + every Update. ~1.4k lines across ai/{behavior,states,navigation,perception,spawning,faction}. Perception emits events; behaviours assign MoveTargets; faction profiles drive aggression & engagement distance.',
    category: 'NPCs',
    files: 'apps/game/src/gameplay/ai/',
    notes: 'Framework complete but unbacked by gameplay: combat "attack" is a log line (no damage system), mining/trading have no economy, flee safe-distance check is TODO.',
    status: 'in-progress',
    sortOrder: 140,
    references: [doc('/docs/gameplay', 'Gameplay Loop'), doc('/docs/agents', 'Agent Lifecycle'), doc('/docs/social', 'Progression & World')],
  },
  {
    id: 'ST1.1',
    title: 'Event Logging System',
    description: 'Capture all player actions (mining, trading, combat, exploration, docking, missions) as structured GameEvents on an event bus.',
    details: 'Framework built: GameEvent enum (7 variants) + log_game_events system registered in NarrativePlugin. BUT no gameplay system emits GameEvents yet, so the bus stays empty.',
    category: 'Narrative',
    files: 'apps/game/src/gameplay/narrative/events.rs',
    notes: 'Next step: wire emitters into mining/docking/trade/combat once those systems exist.',
    status: 'in-progress',
    sortOrder: 150,
    references: [doc('/docs/agents', 'Agent Lifecycle'), doc('/docs/ship-ai', 'Ship AI — Zora')],
  },
  {
    id: 'ST1.3',
    title: 'Campaign History Tracking',
    description: 'Persistent timeline of events with automatic chapter detection, key-moment extraction, and aggregate statistics.',
    details: 'Framework built: CampaignHistory resource + detect_chapters system registered. Maintains chapters, key moments, and per-category statistics. Depends on ST1.1 emitters to actually populate.',
    category: 'Narrative',
    files: 'apps/game/src/gameplay/narrative/history.rs',
    notes: 'History is only as rich as the events fed into it — currently empty.',
    status: 'in-progress',
    sortOrder: 151,
    references: [doc('/docs/agents', 'Agent Lifecycle')],
  },

  // ── TODO ──────────────────────────────────────────────────────────────────
  {
    id: 'I4',
    title: 'Complete In-System Gameplay',
    description: 'Docking operation, mining operation with output, cargo collection, station interactions.',
    details: 'Missing: docking only undocks, mining has no resource output. No station services, no refueling, no repairs.',
    category: 'In-System',
    files: 'apps/game/src/gameplay/in_system/operations.rs',
    notes: 'Docks and mines marked as TODO in operations.rs.',
    status: 'todo',
    sortOrder: 210,
    references: [doc('/docs/gameplay', 'Gameplay Loop'), doc('/docs/economy', 'Economy & Industry')],
  },
  {
    id: 'U2',
    title: 'Flight HUD / In-Game UI',
    description: 'Target reticle, ship status display, operation progress bars, contextual action buttons.',
    details: 'Missing: all in-game UI is commented out. Player has no visual feedback during flight.',
    category: 'UI',
    files: 'apps/game/src/gameplay/in_system/',
    notes: 'UI setup and update systems are commented out in mod.rs.',
    status: 'todo',
    sortOrder: 220,
    references: [doc('/docs/gameplay', 'Gameplay Loop')],
  },
  {
    id: 'M2',
    title: 'Star Map Plugin',
    description: 'Galaxy-scale navigation showing all systems, hyperspace lanes, and current position.',
    details: 'Missing: plugin structure exists but implementation is empty. No camera, no rendering, no interaction.',
    category: 'Navigation',
    files: 'apps/game/src/gameplay/star_map/mod.rs',
    notes: 'File contains only TODO comments and empty plugin struct.',
    status: 'todo',
    sortOrder: 230,
    references: [doc('/docs/gameplay', 'Gameplay Loop')],
  },
  {
    id: 'P2',
    title: 'Physics & Collision',
    description: 'Mass-based interactions, collision detection between ships and objects, spatial queries.',
    details: 'Missing: only basic geometry primitives exist. No collision system, no physics simulation.',
    category: 'Core',
    files: 'apps/game/src/gameplay/physics/mod.rs',
    notes: 'Module exports marker components only. No actual physics systems.',
    status: 'todo',
    sortOrder: 23,
    references: [doc('/docs/architecture', 'Architecture'), doc('/docs/gameplay', 'Gameplay Loop')],
  },
  {
    id: 'R1',
    title: 'Resource System',
    description: 'Ore types, cargo inventory, resource collection during mining.',
    details: 'Missing: no resource types defined, no inventory system, no cargo hold.',
    category: 'Economy',
    files: 'N/A',
    notes: 'No resource or inventory modules exist in codebase.',
    status: 'todo',
    sortOrder: 240,
    references: [doc('/docs/economy', 'Economy & Industry'), doc('/docs/demos/refining', 'Refining demo')],
  },
  {
    id: 'E1',
    title: 'Economy System',
    description: 'Credits, market prices, trading, station markets.',
    details: 'Missing: no economy simulation, no pricing, no trade mechanics.',
    category: 'Economy',
    files: 'N/A',
    notes: 'No economy modules exist in codebase.',
    status: 'todo',
    sortOrder: 241,
    references: [doc('/docs/economy', 'Economy & Industry'), doc('/docs/demos/market', 'Market demo')],
  },
  {
    id: 'C2',
    title: 'Ship Components',
    description: 'Shields, armor, hull, capacitor, power grid, CPU.',
    details: 'Missing: ships have no stats beyond position. No component systems.',
    category: 'Ships',
    files: 'N/A',
    notes: 'Ship is just a mesh with position. No stats or systems.',
    status: 'todo',
    sortOrder: 250,
    references: [doc('/docs/ships', 'Ships & Fitting'), doc('/docs/gameplay', 'Gameplay Loop')],
  },
  {
    id: 'S4',
    title: 'Local Save / Disk Persistence',
    description: 'Continuous local persistence of campaign, character, galaxy, and story state (no manual save button).',
    details: 'Missing: Cargo.toml has only `bevy` — no serde/ron/fs. CampaignDraft + CampaignHistory are in-memory Resources lost on exit. Architecture doc mandates continuous auto-save as the source of truth.',
    category: 'Core',
    files: 'N/A — needs serde + a save module (e.g. gameplay/save.rs)',
    notes: 'Design refs: Architecture ("no save button, persists continuously"), Overview ("local persistence for V1"), AGENTS.md ("V1 is single-player with local persistence").',
    status: 'todo',
    sortOrder: 24,
    references: [doc('/docs/architecture', 'Architecture'), doc('/docs/backend', 'Backend Model'), doc('/docs/overview', 'Overview')],
  },
  {
    id: 'U3',
    title: 'Options / Settings Screen',
    description: 'Settings menu: graphics, audio, controls, accessibility. Reached from the main-menu Options button.',
    details: 'Missing: AppState::Options exists and the main-menu Options button transitions to it, but there are no OnEnter/OnExit/Update systems — selecting it dead-ends.',
    category: 'UI',
    files: 'apps/game/src/state.rs, apps/game/src/ui/main_menu.rs',
    notes: 'State variant + menu button exist; no screen implementation.',
    status: 'todo',
    sortOrder: 231,
    references: [doc('/docs/overview', 'Overview'), doc('/docs/architecture', 'Architecture')],
  },

  // ── BACKLOG ───────────────────────────────────────────────────────────────
  {
    id: 'C3',
    title: 'Combat System',
    description: 'Weapons, damage resolution, shield/armor/hull pools, combat AI, target locking.',
    details: 'Not started: no weapon systems, no damage calculations, no combat state. FTL-style auto-combat planned.',
    category: 'Combat',
    files: 'N/A',
    notes: 'No combat modules exist. Design specifies FTL-style power allocation combat.',
    status: 'backlog',
    sortOrder: 310,
    references: [doc('/docs/gameplay', 'Gameplay Loop'), doc('/docs/ships', 'Ships & Fitting'), doc('/docs/demos/combat', 'Combat demo')],
  },
  {
    id: 'S3',
    title: 'Multiple Ship Types',
    description: 'Frigate, hauler, scout, warship, battleship classes with different stats.',
    details: 'Not started: only generic starter ship mesh exists. No ship catalog or stat variations.',
    category: 'Ships',
    files: 'N/A',
    notes: 'Single cone+box+sphere ship. No classes or variations.',
    status: 'backlog',
    sortOrder: 320,
    references: [doc('/docs/ships', 'Ships & Fitting')],
  },
  {
    id: 'F1',
    title: 'Module Fitting',
    description: 'High/Med/Low slots, CPU/PG constraints, module catalog, fitting screen.',
    details: 'Not started: no fitting system. Design specifies full fitting with drag-and-drop.',
    category: 'Ships',
    files: 'N/A',
    notes: 'Reference: apps/docs/src/prototypes/existing-demos/FittingDemo.tsx',
    status: 'backlog',
    sortOrder: 321,
    references: [doc('/docs/ships', 'Ships & Fitting'), doc('/docs/demos/fitting', 'Fitting demo')],
  },
  {
    id: 'Q1',
    title: 'Quest & Mission System',
    description: 'NPC agents, mission templates (kill, courier, mining), active mission tracking.',
    details: 'Not started: no quest system. Design specifies 6 mission types with rewards.',
    category: 'Content',
    files: 'N/A',
    notes: 'Reference: design docs describe faction quests and mission templates.',
    status: 'backlog',
    sortOrder: 330,
    references: [doc('/docs/gameplay', 'Gameplay Loop'), doc('/docs/social', 'Progression & World'), doc('/docs/demos/bounty', 'Bounty demo')],
  },
  {
    id: 'A1',
    title: 'Faction System',
    description: 'Faction standing, loyalty points, reputation effects, faction-controlled space.',
    details: 'Not started: factions are colors only. No standing or reputation tracking.',
    category: 'Social',
    files: 'N/A',
    notes: 'Factions exist as labels only. No gameplay effects.',
    status: 'backlog',
    sortOrder: 340,
    references: [doc('/docs/social', 'Progression & World'), doc('/docs/gameplay', 'Gameplay Loop')],
  },
  {
    id: 'W1',
    title: 'Dynamic World Events',
    description: 'Random events, anomalies, faction conflicts, world state changes.',
    details: 'Not started: no event system. Design describes 6 event categories.',
    category: 'Content',
    files: 'N/A',
    notes: 'No world event modules exist.',
    status: 'backlog',
    sortOrder: 331,
    references: [doc('/docs/gameplay', 'Gameplay Loop'), doc('/docs/agents', 'Agent Lifecycle')],
  },
  {
    id: 'PR1',
    title: 'Skill & Progression',
    description: 'XP awards, skill catalog (Mining, Industry, Trade, Gunnery, Navigation), level 0-5.',
    details: 'Not started: no XP or skills. Design specifies 5 skills with tier bonuses.',
    category: 'Progression',
    files: 'N/A',
    notes: 'Reference: apps/docs/src/prototypes/existing-demos/ProgressionDemo.tsx',
    status: 'backlog',
    sortOrder: 350,
    references: [doc('/docs/social', 'Progression & World'), doc('/docs/demos/progression', 'Progression demo')],
  },
  {
    id: 'MF1',
    title: 'Manufacturing',
    description: 'Blueprints, production jobs, material requirements, output queues.',
    details: 'Not started: no manufacturing. Design: Ore→Mineral→Component→Module→Ship chain.',
    category: 'Industry',
    files: 'N/A',
    notes: 'Reference: apps/docs/src/prototypes/existing-demos/RefiningDemo.tsx',
    status: 'backlog',
    sortOrder: 360,
    references: [doc('/docs/economy', 'Economy & Industry'), doc('/docs/demos/refining', 'Refining demo')],
  },
  {
    id: 'Z1',
    title: 'Zora Ship AI',
    description: 'AI companion with personality, soul depth, tier progression (0-5).',
    details: 'Not started: no Zora implementation. Design specifies full AI companion system.',
    category: 'Ships',
    files: 'N/A',
    notes: 'Reference: apps/docs/src/prototypes/existing-demos/ZoraDemo.tsx',
    status: 'backlog',
    sortOrder: 370,
    references: [doc('/docs/ship-ai', 'Ship AI — Zora'), doc('/docs/demos/zora', 'Zora demo')],
  },
  {
    id: 'ST1.2',
    title: 'Narrative Synthesis Engine',
    description: 'LLM-based system that weaves events into coherent narrative text.',
    details: 'Stub only: synthesis.rs exists with a placeholder NarrativeSynthesis (available=false) and generate_narrative() returns a TODO string. No LLM/Claude wiring, no event aggregation; NarrativeConfig.use_llm_synthesis defaults off.',
    category: 'Narrative',
    files: 'apps/game/src/gameplay/narrative/synthesis.rs',
    notes: 'Core differentiator. Use Claude API for story generation.',
    status: 'backlog',
    sortOrder: 352,
    references: [doc('/docs/agents', 'Agent Lifecycle'), doc('/docs/ship-ai', 'Ship AI — Zora')],
  },
  {
    id: 'ST1.4',
    title: 'Story Log UI',
    description: 'In-game interface for reading campaign narrative with chapter navigation.',
    details: 'Stub only: ui.rs defines StoryLogUi/ChapterListItem components but setup/update/export fns are TODO placeholders that only log. Not registered in NarrativePlugin.',
    category: 'Narrative',
    files: 'apps/game/src/gameplay/narrative/ui.rs',
    notes: 'Integrates with existing UI system. Should support export/save.',
    status: 'backlog',
    sortOrder: 353,
    references: [doc('/docs/agents', 'Agent Lifecycle')],
  },
  {
    id: 'T1',
    title: 'Tutorial & Onboarding',
    description: 'Guided mission sequence, skip option, tutorial hints, objective tracking.',
    details: 'Not started: no tutorial system. New players have no guidance.',
    category: 'UX',
    files: 'N/A',
    notes: 'Design specifies 7-objective tutorial chain.',
    status: 'backlog',
    sortOrder: 380,
    references: [doc('/docs/overview', 'Overview'), doc('/docs/gameplay', 'Gameplay Loop')],
  },
  {
    id: 'MP1',
    title: 'Multiplayer / Backend',
    description: 'Server auth, multiplayer sessions, cloud persistence.',
    details: 'Removed: multiplayer services deleted. Game is now single-player only with local persistence.',
    category: 'Infrastructure',
    files: 'Removed (services/spacetimedb, services/auth)',
    notes: 'Multiplayer infrastructure has been removed to focus on single-player experience.',
    status: 'backlog',
    sortOrder: 390,
    references: [doc('/docs/architecture', 'Architecture'), doc('/docs/tech-stack', 'Tech Stack')],
  },
];
