// Seed data for ClaudeDo — Claude agent dispatcher
const SEED_LISTS = [
  { id: 'myday', kind: 'smart', icon: 'sun', name: 'My Day' },
  { id: 'running', kind: 'smart', icon: 'pulse', name: 'Running' },
  { id: 'important', kind: 'smart', icon: 'star', name: 'Important' },
  { id: 'planned', kind: 'smart', icon: 'calendar', name: 'Planned' },
  { id: 'review', kind: 'smart', icon: 'eye', name: 'Needs review' },
  { id: 'all', kind: 'smart', icon: 'inbox', name: 'All tasks' },
];

const SEED_USER_LISTS = [
  { id: 'claudedo', icon: 'folder', name: 'ClaudeDo', color: '#6b8e6b' },
  { id: 'tuning-web', icon: 'folder', name: 'tuning-web', color: '#d4a574' },
  { id: 'api-core', icon: 'folder', name: 'api-core', color: '#8b9d7a' },
  { id: 'ops', icon: 'folder', name: 'ops', color: '#7a95a8' },
];

const now = new Date();
const today = now;
const tomorrow = new Date(today); tomorrow.setDate(today.getDate() + 1);
const yesterday = new Date(today); yesterday.setDate(today.getDate() - 1);

const mkISO = (mins) => new Date(Date.now() - mins * 60000).toISOString();

// status: idle | queued | running | review | done | error
const SEED_TASKS = [
  {
    id: 't1',
    title: 'Refactor the auth middleware to use new session store',
    list: 'api-core',
    myDay: true, starred: true,
    due: today.toISOString(),
    notes: 'Swap the old Redis client for the new pool-aware wrapper. Keep the public API stable.',
    tags: ['refactor', 'backend'],
    subtasks: [
      { id: 's1', title: 'Audit call sites', done: true },
      { id: 's2', title: 'Swap client in middleware.ts', done: true },
      { id: 's3', title: 'Update tests', done: false },
      { id: 's4', title: 'Run full test suite', done: false },
    ],
    created: mkISO(120), done: false,
    agent: {
      status: 'running',
      model: 'claude-sonnet-4.5',
      worktree: '~/worktrees/api-core/auth-refactor',
      branch: 'agent/auth-refactor',
      baseBranch: 'main',
      startedAt: mkISO(18),
      commits: 3,
      diff: { files: 7, additions: 142, deletions: 86 },
      turns: 24,
      tokens: 184200,
      log: [
        { t: mkISO(18), k: 'sys',  m: 'Session started · worktree: api-core/auth-refactor' },
        { t: mkISO(17), k: 'tool', m: 'read_file src/middleware/auth.ts' },
        { t: mkISO(17), k: 'tool', m: 'grep "createSessionStore" src/' },
        { t: mkISO(16), k: 'msg',  m: 'Found 12 call sites across 4 modules. Starting with the middleware.' },
        { t: mkISO(14), k: 'tool', m: 'edit_file src/middleware/auth.ts (+48 −22)' },
        { t: mkISO(12), k: 'tool', m: 'edit_file src/lib/session/index.ts (+31 −14)' },
        { t: mkISO(11), k: 'tool', m: 'run_shell "pnpm test auth"' },
        { t: mkISO(10), k: 'stdout', m: '  ✓ auth/basic.test.ts (8)' },
        { t: mkISO(10), k: 'stdout', m: '  ✓ auth/session.test.ts (14)' },
        { t: mkISO(10), k: 'stdout', m: '  ✗ auth/expiry.test.ts (2 failed)' },
        { t: mkISO(9),  k: 'msg',  m: 'Two expiry tests failing — investigating the TTL calculation.' },
        { t: mkISO(6),  k: 'tool', m: 'edit_file src/lib/session/ttl.ts (+12 −4)' },
        { t: mkISO(5),  k: 'tool', m: 'run_shell "pnpm test auth/expiry"' },
        { t: mkISO(4),  k: 'stdout', m: '  ✓ auth/expiry.test.ts (6)' },
        { t: mkISO(3),  k: 'msg',  m: 'Expiry tests passing. Now running full suite…' },
        { t: mkISO(1),  k: 'tool', m: 'run_shell "pnpm test"' },
        { t: mkISO(0.2), k: 'stdout', m: '  Running 284 tests across 41 files…' },
      ],
    },
  },
  {
    id: 't2',
    title: 'Add dark mode toggle to settings page',
    list: 'tuning-web',
    myDay: true, starred: false,
    due: today.toISOString(),
    notes: 'Match the palette from the design system. Persist via localStorage.',
    tags: ['ui'],
    subtasks: [],
    created: mkISO(90), done: false,
    agent: {
      status: 'review',
      model: 'claude-sonnet-4.5',
      worktree: '~/worktrees/tuning-web/dark-mode',
      branch: 'agent/dark-mode',
      baseBranch: 'main',
      startedAt: mkISO(45),
      finishedAt: mkISO(8),
      commits: 2,
      diff: { files: 4, additions: 68, deletions: 12 },
      turns: 14,
      tokens: 92400,
      log: [
        { t: mkISO(45), k: 'sys',  m: 'Session started · worktree: tuning-web/dark-mode' },
        { t: mkISO(44), k: 'tool', m: 'read_file src/pages/settings.tsx' },
        { t: mkISO(42), k: 'tool', m: 'read_file src/theme/tokens.css' },
        { t: mkISO(38), k: 'tool', m: 'edit_file src/pages/settings.tsx (+32 −2)' },
        { t: mkISO(30), k: 'tool', m: 'edit_file src/hooks/useTheme.ts (+24 −0)' },
        { t: mkISO(22), k: 'tool', m: 'edit_file src/theme/tokens.css (+10 −8)' },
        { t: mkISO(14), k: 'tool', m: 'run_shell "pnpm build"' },
        { t: mkISO(12), k: 'stdout', m: '  ✓ Built in 4.2s' },
        { t: mkISO(10), k: 'tool', m: 'run_shell "pnpm test"' },
        { t: mkISO(9),  k: 'stdout', m: '  ✓ 182 tests passed' },
        { t: mkISO(8),  k: 'done', m: 'Ready for review — 2 commits on agent/dark-mode' },
      ],
    },
  },
  {
    id: 't3',
    title: 'Investigate flaky checkout test',
    list: 'tuning-web',
    myDay: true, starred: false,
    due: today.toISOString(),
    notes: 'Fails ~1 in 8 runs on CI. Probably a race in the cart hydration.',
    tags: ['bug', 'tests'],
    subtasks: [],
    created: mkISO(200), done: false,
    agent: {
      status: 'error',
      model: 'claude-sonnet-4.5',
      worktree: '~/worktrees/tuning-web/flaky-checkout',
      branch: 'agent/flaky-checkout',
      baseBranch: 'main',
      startedAt: mkISO(55),
      finishedAt: mkISO(40),
      commits: 0,
      diff: { files: 0, additions: 0, deletions: 0 },
      turns: 6,
      tokens: 28100,
      log: [
        { t: mkISO(55), k: 'sys',  m: 'Session started · worktree: tuning-web/flaky-checkout' },
        { t: mkISO(54), k: 'tool', m: 'run_shell "pnpm test checkout --repeat 20"' },
        { t: mkISO(50), k: 'stdout', m: '  runs: 20 · passes: 18 · failures: 2' },
        { t: mkISO(45), k: 'tool', m: 'read_file src/features/checkout/cart.tsx' },
        { t: mkISO(42), k: 'tool', m: 'run_shell "pnpm tsc --noEmit"' },
        { t: mkISO(41), k: 'stderr', m: '  src/features/checkout/cart.tsx(142,7): TS2339: ...' },
        { t: mkISO(40), k: 'error', m: 'Blocked: cannot reproduce the race locally. Paused for operator input.' },
      ],
    },
  },
  {
    id: 't4',
    title: 'Write migration guide for v3 API',
    list: 'api-core',
    myDay: true, starred: false,
    due: tomorrow.toISOString(),
    notes: '',
    tags: ['docs'],
    subtasks: [],
    created: mkISO(20), done: false,
    agent: {
      status: 'idle',
      model: 'claude-sonnet-4.5',
      worktree: '~/worktrees/api-core/v3-migration-guide',
      branch: 'agent/v3-migration-guide',
      baseBranch: 'main',
      commits: 0,
      diff: { files: 0, additions: 0, deletions: 0 },
      turns: 0,
      tokens: 0,
      log: [
        { t: mkISO(20), k: 'sys', m: 'Worktree ready. Agent not yet dispatched.' },
      ],
    },
  },
  {
    id: 't5',
    title: 'Upgrade Postgres client to v16',
    list: 'ops',
    myDay: true, starred: false,
    due: yesterday.toISOString(),
    notes: 'Coordinate with infra on the rolling restart window.',
    tags: ['infra'],
    subtasks: [],
    created: mkISO(1440), done: false,
    agent: {
      status: 'queued',
      model: 'claude-sonnet-4.5',
      worktree: '~/worktrees/ops/pg-16',
      branch: 'agent/pg-16',
      baseBranch: 'main',
      commits: 0,
      diff: { files: 0, additions: 0, deletions: 0 },
      turns: 0,
      tokens: 0,
      log: [
        { t: mkISO(30), k: 'sys', m: 'Queued · waiting for api-core/auth-refactor to complete.' },
      ],
    },
  },
  {
    id: 't6',
    title: 'Fix favicon serving on preview domains',
    list: 'tuning-web',
    myDay: true, starred: false,
    due: null, notes: '', tags: ['bug'],
    subtasks: [],
    created: mkISO(300),
    done: true, completedAt: mkISO(60),
    agent: {
      status: 'done',
      model: 'claude-sonnet-4.5',
      worktree: '~/worktrees/tuning-web/favicon',
      branch: 'agent/favicon',
      baseBranch: 'main',
      startedAt: mkISO(90),
      finishedAt: mkISO(60),
      commits: 1,
      diff: { files: 2, additions: 14, deletions: 3 },
      turns: 8,
      tokens: 41800,
      mergedInto: 'main',
      log: [
        { t: mkISO(90), k: 'sys',  m: 'Session started' },
        { t: mkISO(75), k: 'tool', m: 'edit_file nginx/preview.conf (+8 −3)' },
        { t: mkISO(70), k: 'tool', m: 'edit_file public/favicon.ico (+6 −0)' },
        { t: mkISO(65), k: 'done', m: 'Merged into main · closed PR #482' },
      ],
    },
  },
];

window.SEED_LISTS = SEED_LISTS;
window.SEED_USER_LISTS = SEED_USER_LISTS;
window.SEED_TASKS = SEED_TASKS;
