export interface FactoryTaskFixture {
  readonly key: string;
  readonly title: string;
  readonly description: string;
  readonly state: "Completed" | "Running" | "Attempt failed" | "Paused" | "Blocked" | "Queued";
  readonly dependsOn: string;
  readonly agentRun: string;
  readonly started: string;
  readonly duration: string;
}

export interface AgentRunFixture {
  readonly id: string;
  readonly task: string;
  readonly attempt: string;
  readonly model: string;
  readonly account: string;
  readonly workspace: string;
  readonly started: string;
  readonly lastActivity: string;
  readonly checkpoint: string;
}

export interface TimelineEventFixture {
  readonly time: string;
  readonly title: string;
  readonly detail: string;
  readonly tone: "green" | "purple" | "blue" | "amber" | "red";
}

export const activeFactoryFixture = {
  id: "FR-001",
  title: "Increment 1 — First complete vertical slice",
  elapsed: "18m 42s",
  goal: "Dogfood the first complete lifecycle",
  scope: "web-app, api, worker",
  tasks: [
    {
      key: "A",
      title: "Bootstrap environment",
      description: "Create workspace, install deps, setup",
      state: "Completed",
      dependsOn: "—",
      agentRun: "AR-016",
      started: "15:28",
      duration: "3m 12s",
    },
    {
      key: "B",
      title: "Implement API",
      description: "Build and test core API endpoints",
      state: "Running",
      dependsOn: "A",
      agentRun: "AR-017",
      started: "15:32",
      duration: "12m 8s",
    },
    {
      key: "C",
      title: "Build frontend",
      description: "Implement UI and run tests",
      state: "Running",
      dependsOn: "A",
      agentRun: "AR-018",
      started: "15:33",
      duration: "10m 47s",
    },
    {
      key: "D",
      title: "Integration tests",
      description: "End-to-end tests",
      state: "Blocked",
      dependsOn: "B",
      agentRun: "—",
      started: "—",
      duration: "—",
    },
    {
      key: "E",
      title: "Prepare release",
      description: "Build artifacts and publish",
      state: "Queued",
      dependsOn: "D",
      agentRun: "—",
      started: "—",
      duration: "—",
    },
  ] satisfies readonly FactoryTaskFixture[],
  agents: [
    {
      id: "AR-017",
      task: "Task B — Implement API",
      attempt: "Attempt 1 / 3",
      model: "Claude 3.5 Sonnet",
      account: "AWP-Dev",
      workspace: "ws-fr001-017",
      started: "15:32 (12m 8s)",
      lastActivity: "Running tests (72%)",
      checkpoint: "Saved (8m ago)",
    },
    {
      id: "AR-018",
      task: "Task C — Build frontend",
      attempt: "Attempt 1 / 3",
      model: "GPT-4o",
      account: "AWP-Dev",
      workspace: "ws-fr001-018",
      started: "15:33 (10m 47s)",
      lastActivity: "Installing dependencies (61%)",
      checkpoint: "Saved (6m ago)",
    },
  ] satisfies readonly AgentRunFixture[],
  timeline: [
    {
      time: "15:28",
      title: "Workspace created",
      detail: "ws-fr001-017 for FactoryRun FR-001",
      tone: "green",
    },
    { time: "15:31", title: "Task A completed", detail: "Bootstrap environment", tone: "green" },
    {
      time: "15:32",
      title: "Attempts started",
      detail: "AR-017 (Task B) and AR-018 (Task C)",
      tone: "purple",
    },
    {
      time: "15:40",
      title: "Source changes checkpointed",
      detail: "Commit a7f3c9e (B and C)",
      tone: "blue",
    },
    {
      time: "15:43",
      title: "Test step finished",
      detail: "Backend unit tests (B) 72%",
      tone: "blue",
    },
    {
      time: "15:46",
      title: "Latest progress",
      detail: "B: running tests (72%) • C: installing deps (61%)",
      tone: "purple",
    },
  ] satisfies readonly TimelineEventFixture[],
} as const;

export const recoveryFactoryFixture = {
  ...activeFactoryFixture,
  elapsed: "19m 11s",
  failedAt: "15:47:21",
  failureClass: "infrastructure",
  failureCause: "workspace_heartbeat_expired",
  failureReason: "Execution pod for Task B stopped responding after heartbeat expiry.",
  retryDisposition: "retryable-new-attempt",
  exactSource: "checkpoint:a7f3c9e",
  checkpoint: "a7f3c9e",
  preservedFiles: 14,
  tasks: [
    {
      key: "A",
      title: "Bootstrap environment",
      description: "Create workspace, install deps, setup",
      state: "Completed",
      dependsOn: "—",
      agentRun: "AR-016",
      started: "15:28",
      duration: "3m 12s",
    },
    {
      key: "B",
      title: "Implement API",
      description: "Build and test core API endpoints",
      state: "Attempt failed",
      dependsOn: "A",
      agentRun: "AR-017",
      started: "15:32",
      duration: "15m 21s",
    },
    {
      key: "C",
      title: "Build frontend",
      description: "Still healthy; paused at safe checkpoint",
      state: "Paused",
      dependsOn: "A",
      agentRun: "AR-018",
      started: "15:33",
      duration: "14m 08s",
    },
    {
      key: "D",
      title: "Integration tests",
      description: "Waiting for recovered Task B",
      state: "Blocked",
      dependsOn: "B",
      agentRun: "—",
      started: "—",
      duration: "—",
    },
    {
      key: "E",
      title: "Prepare release",
      description: "Build artifacts and publish",
      state: "Queued",
      dependsOn: "D",
      agentRun: "—",
      started: "—",
      duration: "—",
    },
  ] satisfies readonly FactoryTaskFixture[],
  timeline: [
    {
      time: "15:40",
      title: "Source changes checkpointed",
      detail: "a7f3c9e · 14 modified files persisted",
      tone: "green",
    },
    {
      time: "15:47",
      title: "Heartbeat expired",
      detail: "Attempt 1 marked failed; unsafe downstream dispatch stopped",
      tone: "red",
    },
    {
      time: "15:47",
      title: "Recovery plan prepared",
      detail: "Task C paused safely; D/E remain blocked by dependency graph",
      tone: "amber",
    },
    {
      time: "15:48",
      title: "Attempt 2 ready",
      detail: "Will remount preserved WIP and continue the logical AgentRun",
      tone: "purple",
    },
  ] satisfies readonly TimelineEventFixture[],
} as const;

export const waitingFactoryFixture = {
  ...activeFactoryFixture,
  elapsed: "19m 02s",
  waitingSince: "15:47",
  waitingClass: "provider-capacity",
  waitingReason: "Eligible execution capacity is temporarily unavailable for Task B.",
  nextAutomaticAction: "Re-evaluate eligible capacity in 30s; no owner action required.",
  checkpoint: "a7f3c9e",
  tasks: [
    activeFactoryFixture.tasks[0]!,
    {
      ...activeFactoryFixture.tasks[1]!,
      state: "Paused" as const,
      description: "Paused at a safe checkpoint while capacity is unavailable",
    },
    {
      ...activeFactoryFixture.tasks[2]!,
      state: "Paused" as const,
      description: "Paused at a safe checkpoint while capacity is unavailable",
    },
    activeFactoryFixture.tasks[3]!,
    activeFactoryFixture.tasks[4]!,
  ] satisfies readonly FactoryTaskFixture[],
  timeline: [
    {
      time: "15:40",
      title: "Source changes checkpointed",
      detail: "a7f3c9e · accepted WIP persisted",
      tone: "green",
    },
    {
      time: "15:47",
      title: "Capacity wait entered",
      detail: "No eligible execution slot currently available; no Task marked failed",
      tone: "amber",
    },
    {
      time: "15:47",
      title: "Automatic recheck scheduled",
      detail: "AWP will re-evaluate capacity without owner relay",
      tone: "blue",
    },
  ] satisfies readonly TimelineEventFixture[],
} as const;

export const reviewFixture = {
  title: "Dependency-aware queue implementation",
  plan: "Increment 1 — First complete vertical slice",
  task: "Queue legality + DAG validation",
  base: "main@faec4c7",
  files: [
    ["src/application/queue.ts", "+96 −20"],
    ["src/domain/task.ts", "+61 −19"],
    ["src/domain/dependency.ts", "+86 −0"],
    ["src/ui/queue-dnd.ts", "+72 −8"],
    ["tests/queue.test.ts", "+128 −2"],
    ["docs/queue.md", "+34 −0"],
  ] as const,
  changesRequested: {
    changeSet: "CS-001",
    review: "RV-001",
    candidate: "8bd27ae",
    blockingFinding: "Cross-Plan prerequisite omitted from legal range",
    recommendation: "Error copy should name prerequisite",
  },
  ready: {
    changeSet: "CS-002",
    review: "RV-002",
    candidate: "94c11bf",
    target: "main",
  },
  merged: {
    changeSet: "CS-002",
    review: "RV-002",
    merge: "M-001",
    candidate: "94c11bf",
    result: "4b8e2c1",
    target: "main",
    completed: "16:08",
  },
} as const;
