import type { PromptPermissionDetails } from '@gotgenes/pi-permission-system'
import { describe, expect, it } from 'vitest'
import { autoReviewConfigSchema } from '../src/config.js'
import { buildReviewPrompt } from '../src/prompt.js'

const details: PromptPermissionDetails = {
  requestId: 'request-1',
  source: 'tool_call',
  agentName: null,
  toolName: 'bash',
  command: 'git push origin main',
  surface: 'bash',
  payload: {
    kind: 'bash',
    request: {
      requester: { agentName: null, forwarded: false, sessionId: null },
      surface: 'bash',
      toolName: 'bash',
      invokedToolName: null,
      value: 'git push origin main',
      matchedPattern: 'git *',
      commandContext: null,
      executedUnit: null,
    },
    evidence: [{ label: 'command', text: 'git push origin main', detail: null }],
    annotations: [],
  },
}

describe('review prompt', () => {
  it('preserves the current pi-permission-system structured request payload', () => {
    const prompt = buildReviewPrompt(
      autoReviewConfigSchema.parse({}),
      {
        entries: [],
        omittedCount: 0,
        stats: {
          transcriptEntriesRetained: 0,
          transcriptEntriesOmitted: 0,
          transcriptEntriesTruncated: 0,
          directUserEntriesRetained: 0,
          directUserEntriesOmitted: 0,
          directUserEntriesTruncated: 0,
          userInteractionEntriesRetained: 0,
          userInteractionEntriesOmitted: 0,
          userInteractionEntriesTruncated: 0,
          latestTrustedEntryRetained: false,
        },
      },
      details,
    )

    expect(prompt.userPrompt).toContain('"payload"')
    expect(prompt.userPrompt).toContain('"matchedPattern": "git *"')
    expect(prompt.userPrompt).toContain('"value": "git push origin main"')
  })
})
