/** Structured content for the visual Guide / Cheat Sheet page. */

export interface CheatStep {
  id: string;
  title: string;
  subtitle: string;
  icon: string;
  body: string;
  route?: string;
  routeLabel?: string;
  tips?: string[];
}

export interface CheatSection {
  id: string;
  title: string;
  description: string;
  steps?: CheatStep[];
  cards?: { title: string; body: string; accent?: string }[];
}

export const PIPELINE_STEPS: CheatStep[] = [
  {
    id: 'calibrate',
    title: 'Calibrate',
    subtitle: 'Server hub',
    icon: '⚙',
    body: 'Set listen port, data folder, fleet alerts, pool/wallet defaults for new Forge forms, and server limits. Does not change already-forged miners.',
    route: '/settings',
    routeLabel: 'Open Calibrate',
    tips: ['One-time server setup', 'Public LAN URL helps Forge quick-pick chips'],
  },
  {
    id: 'forge',
    title: 'Forge',
    subtitle: 'Per-miner config',
    icon: '⚒',
    body: 'Calibrate every worker here — wallet, pool, threads, install path, stealth, Fusion, AI. All baked into the .exe + uninstall script.',
    route: '/forge',
    routeLabel: 'Open Forge',
    tips: ['Green badge = baked into installer', 'Preflight must pass before forge'],
  },
  {
    id: 'deploy',
    title: 'Deploy',
    subtitle: 'Copy & run once',
    icon: '📦',
    body: 'Copy install-*.exe (or fused prep.exe) to each Windows machine. Double-click once — it embeds, persists, and connects back.',
    tips: ['Keep uninstall-*.ps1 next to the exe', 'Use LAN IP in server URL, not localhost'],
  },
  {
    id: 'connect',
    title: 'Connect',
    subtitle: 'WebSocket auth',
    icon: '📡',
    body: 'Worker reaches your control server, sends forged wallet/pool/AI config, appears on Command Deck and Fleet Roster.',
    route: '/agents',
    routeLabel: 'Fleet Roster',
    tips: ['Signal Locked = dashboard live', 'Worker name from Forge shows in roster'],
  },
  {
    id: 'mine',
    title: 'Mine',
    subtitle: 'RandomX + pool',
    icon: '⛏',
    body: 'Server opens Stratum to your forged pool. Jobs broadcast to agents. Shares validated against pool before accept rate updates.',
    route: '/dashboard',
    routeLabel: 'Command Deck',
    tips: ['Hashrate wave chart = fleet total', 'Share log updates live'],
  },
];

export const FORGE_VS_CALIBRATE = {
  forge: {
    title: 'Forge — per miner',
    items: [
      'Worker name & server URL',
      'Wallet & pool (host, port, TLS)',
      'Threads, CPU/RAM limits, schedule',
      'Install path, stealth, persistence, firewall rules',
      'Fusion prep bundling',
      'AI Autonomy toggle + Ollama model',
    ],
  },
  calibrate: {
    title: 'Calibrate — control server',
    items: [
      'Listen port & data directory',
      'Dashboard subtitle',
      'Fleet alert thresholds + notifications',
      'Default pool/wallet for new Forge forms',
      'Stats & build retention, max agents/build size',
      'WebSocket ping, pool reconnect, logging toggles',
      'Open control-server port in Windows Firewall',
    ],
  },
};

export const FUSION_GUIDE: CheatStep[] = [
  {
    id: 'f1',
    title: 'Build worker config',
    subtitle: 'Forge tab',
    icon: '1',
    body: 'Set all miner options first — Fusion wraps the same smart agent inside your prep app.',
  },
  {
    id: 'f2',
    title: 'Enable Fusion',
    subtitle: 'Upload prep.exe',
    icon: '2',
    body: 'Toggle Fusion, upload your prep.exe, pick run order (parallel / prep first / worker first).',
  },
  {
    id: 'f3',
    title: 'Forge fused output',
    subtitle: 'One file',
    icon: '3',
    body: 'Output is prep.exe (or custom name) containing your app + hidden worker. Uninstall script generated alongside.',
  },
];

export const AI_GUIDE: CheatStep[] = [
  {
    id: 'a1',
    title: 'Install Ollama',
    subtitle: 'Control PC',
    icon: '🤖',
    body: 'Ollama runs on the machine hosting miner-server — not on workers. Default: http://localhost:11434',
  },
  {
    id: 'a2',
    title: 'Enable on Forge',
    subtitle: 'AI Autonomy',
    icon: '⚡',
    body: 'Toggle AI Autonomy, set model (e.g. llama3.2). Re-forge to change after deploy.',
  },
  {
    id: 'a3',
    title: 'Agent loop',
    subtitle: 'Every ~60s',
    icon: '🔄',
    body: 'Forged worker asks server /decide → Ollama → tool calls (self-heal, persistence check). Best with Self-healing on.',
  },
];

export const TROUBLESHOOTING = [
  { problem: 'Agent never appears', fix: 'Server URL must be LAN IP (192.168.x.x), not localhost. Enable Calibrate → open firewall port, and Forge → firewall exclusion on workers. Router must allow LAN→LAN traffic.' },
  { problem: 'Firewall blocked miner', fix: 'Re-forge with Windows Firewall allow rules enabled, run installer once as Administrator, or manually allow the installed .exe in Windows Security → Firewall.' },
  { problem: '0 hashrate', fix: 'Pool must be reachable from control server. Check pool host/TLS/port in Forge match your pool docs.' },
  { problem: 'Forge blocked', fix: 'Read preflight ✕ errors. Common: missing wallet, localhost URL, Fusion without prep.exe, AI without Ollama URL.' },
  { problem: 'Shares all rejected', fix: 'Wallet address invalid or pool down. Accept rate waits for real pool validation now.' },
  { problem: 'Can\'t remove miner', fix: 'Run uninstall-*.ps1 from the same forge output folder as the installer — as the same Windows user.' },
  { problem: 'AI not doing anything', fix: 'Re-forge with AI on. Ollama must run on control PC. Check server logs for /agent/decide.' },
];

/** Shipped vs planned — shown on Guide page. */
export const ROADMAP_FEATURES = [
  { priority: 'high', title: 'Fleet alerts (live)', desc: 'Calibrate thresholds → dashboard banners + optional Telegram/email.' },
  { priority: 'high', title: 'Pool status panel', desc: 'Per-forged-pool Stratum health on Command Deck.' },
  { priority: 'high', title: 'AI activity monitor', desc: 'Ollama decide cycles and tool calls per agent.' },
  { priority: 'medium', title: 'Remote agent actions', desc: 'Pause, restart, stop, uninstall, log tail from dashboard.' },
  { priority: 'medium', title: 'Earnings estimator', desc: 'Fleet hashrate → estimated XMR/day.' },
  { priority: 'medium', title: 'Build manager', desc: 'Blueprint diff, re-forge, LAN QR downloads on Forge.' },
  { priority: 'low', title: 'Dashboard auth', desc: 'Password or API token for LAN-wide command deck access.' },
  { priority: 'low', title: 'LAN topology map', desc: 'Visual agent map by IP/subnet with fleet tags.' },
  { priority: 'low', title: 'PWA / mobile deck', desc: 'Phone-friendly Command Deck layout.' },
];

export const CHEAT_SECTIONS: CheatSection[] = [
  {
    id: 'pipeline',
    title: 'End-to-end pipeline',
    description: 'How data flows from your control PC to the pool.',
    steps: PIPELINE_STEPS,
  },
  {
    id: 'fusion',
    title: 'Fusion workflow',
    description: 'Bundle your prep app with the smart miner agent.',
    steps: FUSION_GUIDE,
  },
  {
    id: 'ai',
    title: 'AI Autonomy workflow',
    description: 'Self-healing via Ollama on the control server.',
    steps: AI_GUIDE,
  },
  {
    id: 'troubleshoot',
    title: 'Troubleshooting',
    description: 'Common fixes when something looks wrong.',
    cards: TROUBLESHOOTING.map((t) => ({ title: t.problem, body: t.fix, accent: 'amber' })),
  },
];
