import type {
  PullRequestDetail,
  PullRequestView,
  PullRequestViewer,
} from '../api/pull-requests'
import type { CradlePullRequest } from '../use-pull-requests'

export const pullRequestFixtureNow = Date.UTC(2026, 6, 24, 12, 0, 0)

export const pullRequestViewerFixture = {
  login: 'cradle-maintainer',
  avatarUrl: '/icon.png',
  url: 'https://github.com/cradle-maintainer',
} satisfies PullRequestViewer

const pullRequestViews = [
  {
    owner: 'cradle',
    repo: 'cradle-app',
    number: 71,
    url: 'https://github.com/cradle/cradle-app/pull/71',
    title: 'Extract fixture-driven rendering seams',
    isDraft: false,
    state: 'open',
    merged: false,
    headRef: 'cradle/wt/storybook-views',
    baseRef: 'main',
    headSha: 'ab12cd34',
    createdAt: Math.floor((pullRequestFixtureNow - 3 * 86_400_000) / 1000),
    updatedAt: Math.floor((pullRequestFixtureNow - 35 * 60_000) / 1000),
    author: {
      login: 'cradle-maintainer',
      avatarUrl: '/icon.png',
      url: 'https://github.com/cradle-maintainer',
    },
    additions: 824,
    deletions: 310,
    checksState: 'success',
  },
  {
    owner: 'open-source-labs',
    repo: 'runtime-kit',
    number: 184,
    url: 'https://github.com/open-source-labs/runtime-kit/pull/184',
    title: 'Preserve streaming state across runtime reconnects',
    isDraft: true,
    state: 'open',
    merged: false,
    headRef: 'fix/runtime-reconnect',
    baseRef: 'main',
    headSha: 'cd34ef56',
    createdAt: Math.floor((pullRequestFixtureNow - 5 * 86_400_000) / 1000),
    updatedAt: Math.floor((pullRequestFixtureNow - 26 * 60 * 60_000) / 1000),
    author: {
      login: 'runtime-contributor',
      avatarUrl: '/icon.png',
      url: 'https://github.com/runtime-contributor',
    },
    additions: 192,
    deletions: 48,
    checksState: 'pending',
  },
  {
    owner: 'cradle',
    repo: 'plugin-sdk',
    number: 56,
    url: 'https://github.com/cradle/plugin-sdk/pull/56',
    title: 'Add typed provider capability descriptors',
    isDraft: false,
    state: 'closed',
    merged: true,
    headRef: 'feat/provider-capabilities',
    baseRef: 'main',
    headSha: 'ef56ab78',
    createdAt: Math.floor((pullRequestFixtureNow - 12 * 86_400_000) / 1000),
    updatedAt: Math.floor((pullRequestFixtureNow - 4 * 86_400_000) / 1000),
    author: {
      login: 'sdk-owner',
      avatarUrl: '/icon.png',
      url: 'https://github.com/sdk-owner',
    },
    additions: 436,
    deletions: 87,
    checksState: 'success',
  },
  {
    owner: 'cradle',
    repo: 'docs',
    number: 29,
    url: 'https://github.com/cradle/docs/pull/29',
    title: 'Document local runtime isolation guarantees',
    isDraft: false,
    state: 'closed',
    merged: false,
    headRef: 'docs/runtime-isolation',
    baseRef: 'main',
    headSha: '9876abcd',
    createdAt: Math.floor((pullRequestFixtureNow - 35 * 86_400_000) / 1000),
    updatedAt: Math.floor((pullRequestFixtureNow - 18 * 86_400_000) / 1000),
    author: null,
    additions: 76,
    deletions: 12,
    checksState: 'failure',
  },
] satisfies PullRequestView[]

export const pullRequestEntriesFixture = [
  {
    id: 'cradle/cradle-app#71',
    role: 'authored',
    pullRequest: pullRequestViews[0],
    workId: 'work-storybook',
    primarySessionId: 'session-storybook',
  },
  {
    id: 'open-source-labs/runtime-kit#184',
    role: 'reviewing',
    pullRequest: pullRequestViews[1],
  },
  {
    id: 'cradle/plugin-sdk#56',
    role: 'authored',
    pullRequest: pullRequestViews[2],
  },
  {
    id: 'cradle/docs#29',
    role: 'reviewing',
    pullRequest: pullRequestViews[3],
  },
] satisfies CradlePullRequest[]

export const pullRequestDetailFixture = {
  pullRequest: {
    ...pullRequestViews[0],
    author: {
      login: 'cradle-maintainer',
      avatarUrl: '/icon.png',
      url: 'https://github.com/cradle-maintainer',
    },
    additions: 824,
    deletions: 310,
    body: [
      '## Summary',
      '',
      'Moves user-visible Pull Request surfaces behind pure props interfaces.',
      '',
      '- Adds stable Storybook fixtures',
      '- Keeps query and navigation ownership in adapters',
    ].join('\n'),
    changedFiles: 23,
    commits: 7,
    comments: 4,
    reviewComments: 2,
    mergeable: true,
    mergeableState: 'clean',
    allowedMergeMethods: ['merge', 'squash', 'rebase'],
    mergeBlockers: [],
    canMerge: true,
    createdAtIso: '2026-07-21T08:00:00.000Z',
    updatedAtIso: '2026-07-24T11:25:00.000Z',
    closedAtIso: null,
    mergedAtIso: null,
    reviewers: [{
      login: 'review-owner',
      avatarUrl: '/icon.png',
      url: 'https://github.com/review-owner',
    }],
    assignees: [{
      login: 'cradle-maintainer',
      avatarUrl: '/icon.png',
      url: 'https://github.com/cradle-maintainer',
    }],
    labels: [
      { name: 'frontend', color: '0e8a16' },
      { name: 'architecture', color: '5319e7' },
    ],
    checks: [
      {
        id: 'check-lint',
        name: 'Lint and typecheck',
        status: 'completed',
        conclusion: 'success',
        url: 'https://github.com/cradle/cradle-app/actions',
      },
      {
        id: 'check-build',
        name: 'Storybook build',
        status: 'completed',
        conclusion: 'success',
        url: 'https://github.com/cradle/cradle-app/actions',
      },
    ],
  },
  timeline: [
    {
      id: 'comment-1',
      kind: 'comment',
      author: {
        login: 'review-owner',
        avatarUrl: '/icon.png',
        url: 'https://github.com/review-owner',
      },
      body: 'The new View interface is small enough to fixture without runtime decorators.',
      state: null,
      createdAt: '2026-07-22T09:15:00.000Z',
      url: 'https://github.com/cradle/cradle-app/pull/71#issuecomment-1',
    },
    {
      id: 'review-1',
      kind: 'review',
      author: {
        login: 'review-owner',
        avatarUrl: '/icon.png',
        url: 'https://github.com/review-owner',
      },
      body: 'Verified the desktop and mobile layouts.',
      state: 'APPROVED',
      createdAt: '2026-07-24T10:40:00.000Z',
      url: 'https://github.com/cradle/cradle-app/pull/71#pullrequestreview-1',
    },
  ],
  files: [
    {
      sha: 'file-sha-1',
      filename: 'apps/web/src/features/pull-requests/pull-requests-page-view.tsx',
      previousFilename: null,
      status: 'added',
      additions: 18,
      deletions: 0,
      changes: 18,
      patch: [
        '@@ -0,0 +1,4 @@',
        '+export function PullRequestsPageView() {',
        '+  return <main>Pull requests</main>',
        '+}',
      ].join('\n'),
      blobUrl: 'https://github.com/cradle/cradle-app/blob/main/pull-requests-page-view.tsx',
      rawUrl: 'https://raw.githubusercontent.com/cradle/cradle-app/main/pull-requests-page-view.tsx',
    },
    {
      sha: 'file-sha-2',
      filename: 'apps/web/src/features/pull-requests/fixtures/pull-requests.ts',
      previousFilename: null,
      status: 'added',
      additions: 42,
      deletions: 0,
      changes: 42,
      patch: null,
      blobUrl: 'https://github.com/cradle/cradle-app/blob/main/pull-requests.ts',
      rawUrl: 'https://raw.githubusercontent.com/cradle/cradle-app/main/pull-requests.ts',
    },
  ],
} satisfies PullRequestDetail
