import type { ClusterQueueModel, FleetHost, OffloadControlModel, RemoteJob } from '../offload-types'

/** Pinned anchor so fixture `probedAt` values agree between SSR and client hydration. */
export const FIXTURE_ANCHOR_MS = Date.parse('2026-08-16T04:00:00.000Z')

export const FLEET_DEBIAN1: FleetHost = {
  host: 'debian1',
  registryState: 'reachable',
  role: 'builder',
  state: 'available',
  primary: true,
  enrolling: false,
  load: 3.9,
  cores: 8,
  coreLoads: [92, 88, 70, 45, 30, 22, 18, 10],
  running: 0,
  slotsFree: 8,
  slotsTotal: 8,
  builds24h: 214,
  sessions: 3,
  remoteWork: { agentSeats: 4, remoteBuildJobs: 2, offloadShells: 1 },
  dispatchAccept: false,
  capability: {
    probes: [
      { name: 'tsc', ok: true, version: '5.9.3' },
      { name: 'vitest', ok: true },
      { name: 'pnpm', ok: true },
      { name: 'playwright browsers', ok: false },
    ],
    circuitOpen: true,
    missingCommand: 'playwright browsers',
  },
  memUsedBytes: 10_517_506_048,
  memTotalBytes: 34_359_738_368,
  swapUsedBytes: 0,
  swapTotalBytes: 8_589_934_592,
  netRxBytesPerSecond: 6_400_000,
  netTxBytesPerSecond: 46_327_808,
  disk: [{ mountpoint: '/', freeBytes: 95_443_783_680, sizeBytes: 536_870_912_000 }],
  temp: { pkg: 61, max: 66, crit: 95 },
  guard: {
    stall: { some60: 4.2, full60: 1.1, full300: 0.4 },
    tmpUsedBytes: 69_464_064,
    tmpSizeBytes: 16_714_129_408,
    workSlices: [
      { slice: 'agent.slice', memoryBytes: 3_221_225_472, pidsCurrent: 47, oomKillTotal: 2 },
      { slice: 'build.slice', memoryBytes: 0, pidsCurrent: 0, oomKillTotal: 0 },
    ],
  },
  parity: {
    verdict: 'converged',
    detail: 'converged b057be1cca654a1b config-only (credentials not distributed)',
    probedAt: new Date(FIXTURE_ANCHOR_MS - 4 * 60_000).toISOString(),
  },
}

export const FLEET_CONFIG_DRIFTED: FleetHost = {
  ...FLEET_DEBIAN1,
  host: 'debian3',
  parity: {
    verdict: 'drifted',
    detail: 'drifted config=87819cd0867f67bb/want=b057be1cca654a1b',
    probedAt: new Date(FIXTURE_ANCHOR_MS - 11 * 60_000).toISOString(),
  },
}

export const FLEET_CONFIG_UNREACHABLE: FleetHost = {
  ...FLEET_DEBIAN1,
  host: 'debian4',
  parity: {
    verdict: 'unreachable',
    detail: 'unreachable (registry marks it reachable — that is itself drift)',
    probedAt: new Date(FIXTURE_ANCHOR_MS - 3 * 3_600_000).toISOString(),
  },
}

export const FLEET_LAPTOP: FleetHost = {
  host: 'laptop',
  registryState: 'reachable',
  role: 'workstation',
  state: 'available',
  primary: false,
  enrolling: false,
  load: 16,
  cores: 16,
  coreLoads: [99, 97, 96, 94],
  running: 1,
  slotsFree: 3,
  slotsTotal: 4,
  builds24h: 9,
  sessions: 2,
  remoteWork: { agentSeats: 0, remoteBuildJobs: 1, offloadShells: 0 },
  dispatchAccept: false,
  capability: { probes: [{ name: 'full toolchain', ok: true }] },
  memUsedBytes: 32_317_718_528,
  memTotalBytes: 34_359_738_368,
  swapUsedBytes: 4_509_949_952,
  swapTotalBytes: 8_589_934_592,
  netRxBytesPerSecond: 18_400_000,
  netTxBytesPerSecond: 2_100_000,
  disk: [
    { mountpoint: '/', freeBytes: 117_374_182_400, sizeBytes: 549_755_813_888 },
    { mountpoint: '/home', freeBytes: 133_946_818_560, sizeBytes: 549_755_813_888 },
  ],
  temp: { pkg: 79, max: 88, crit: 100 },
}

export const FLEET_DEBIAN2_JOINING: FleetHost = {
  host: 'debian2',
  registryState: 'reachable',
  role: 'builder',
  state: 'restoring',
  primary: false,
  enrolling: true,
  load: null,
  cores: null,
  coreLoads: [],
  running: null,
  slotsFree: null,
  slotsTotal: null,
  builds24h: null,
  sessions: null,
  remoteWork: null,
  dispatchAccept: null,
  capability: { probes: [] },
  memUsedBytes: null,
  memTotalBytes: null,
  swapUsedBytes: null,
  swapTotalBytes: null,
  netRxBytesPerSecond: null,
  netTxBytesPerSecond: null,
  disk: [],
  temp: { pkg: null, max: null, crit: null },
}

export const FLEET_PROBE_FAILING: FleetHost = {
  ...FLEET_DEBIAN2_JOINING,
  host: 'debian3',
  capability: {
    probes: [
      { name: 'storage', ok: true },
      { name: 'runner', ok: true },
      { name: 'offload', ok: true },
      {
        name: 'capability',
        ok: false,
        detail: 'ssh debian3:2222 exited 255 (ssh transport, auth, or host-key failure)',
        checkedAt: '2026-08-08T03:00:00.000Z',
      },
      {
        name: 'telemetry',
        ok: false,
        detail: 'telemetry is 600s old (max 90s)',
        checkedAt: '2026-08-08T03:00:00.000Z',
      },
    ],
  },
}

export const FLEET_CRIT_TEMP: FleetHost = {
  ...FLEET_DEBIAN1,
  coreLoads: [95, 90, 85, 80],
  temp: { pkg: 96, max: 98, crit: 95 },
}

export const CLUSTER_QUEUE_FIXTURE: ClusterQueueModel = {
  depth: 6,
  oldestAgeSeconds: 11_520,
  p95AgeSeconds: 8,
  sloSeconds: 300,
  dispatchTarget: 'debian1',
  spill: { active: true, stale: true },
  wedge: { host: 'debian1', detail: 'slot-0 held by dead pid 2987388' },
  tickets: [
    {
      position: 1,
      key: 'tsc-2279',
      repo: 'multideal',
      owner: { pid: 2279, starttime: 1_721_280_000, label: 'claude·2279' },
      enqueueAgeSeconds: 11_520,
      state: 'queued',
      dispatchTarget: 'debian1',
    },
    {
      position: 2,
      key: 'vitest-3341',
      repo: 'multideal',
      owner: { pid: 3341, starttime: 1_721_280_240, label: 'claude·3341' },
      enqueueAgeSeconds: 11_280,
      state: 'queued',
      dispatchTarget: 'debian1',
    },
  ],
}

export const REMOTE_JOBS_FIXTURE: RemoteJob[] = [
  {
    id: 'rb-8f2a1c',
    repo: 'multideal',
    snapshot: 'e3b1@4188',
    stage: 'building',
    host: 'debian1',
    rc: null,
    pullBytes: null,
    pullDurationSeconds: null,
    publication: { state: 'none' },
  },
  {
    id: 'rb-4e77b0',
    repo: 'zync',
    snapshot: '1f8e@4179',
    stage: 'failed',
    host: 'debian1',
    rc: 127,
    pullBytes: null,
    pullDurationSeconds: null,
    publication: { state: 'none', reason: 'tsc not found' },
  },
]

export const OFFLOAD_CONTROL_FIXTURE: OffloadControlModel = {
  desired: 'available',
  observed: 'available',
  revision: 4192,
  lease: { active: false, expired: false, host: null, reason: null },
  reconciler: { healthy: true, lastAt: '2026-07-18T06:14:00.000Z' },
  dispatch: { state: 'wedged', detail: 'slot-0 held by dead pid 2987388', host: 'debian1' },
  spill: { active: true, stale: true },
  capabilityProbes: [
    { name: 'tsc 5.9.3', ok: true },
    { name: 'vitest', ok: true },
    { name: 'pnpm', ok: true },
    { name: 'disk 91G', ok: true },
    { name: 'playwright browsers', ok: false },
  ],
  actions: [
    { label: 'Drain box', verb: 'box-drain', danger: true },
    { label: 'Restore box', verb: 'box-restore' },
    { label: 'Quarantine host', verb: 'host-quarantine' },
  ],
}
