/**
 * False Positive Test Fixtures
 * Files that should NOT generate high-severity findings
 */

import type { TestFixture } from '../types'

/**
 * Test/Mock files should be ignored
 */
export const testFileFixture: TestFixture = {
  name: 'Test File - Should Not Flag',
  expectFindings: false,
  description: 'Test files with mock data should not generate high-severity findings',
  file: {
    path: 'src/__tests__/auth.test.ts',
    content: `
// Test file - all these should be SAFE
const TEST_API_KEY = "sk-test-12345"
const MOCK_SECRET = "mock-secret-for-testing"

describe('Authentication', () => {
  it('should authenticate with valid key', async () => {
    const result = await authenticate(TEST_API_KEY)
    expect(result).toBeTruthy()
  })

  it('should reject eval for testing', () => {
    // Testing eval handling
    expect(() => eval('1+1')).not.toThrow()
  })
})
`,
    language: 'typescript',
    size: 400,
  },
}

/**
 * Example/documentation files should be ignored
 */
export const exampleFileFixture: TestFixture = {
  name: 'Example File - Should Not Flag',
  expectFindings: false,
  description: 'Example files with placeholder values should not be flagged',
  file: {
    path: 'examples/getting-started.ts',
    content: `
// Example file - all these should be SAFE
const EXAMPLE_API_KEY = "your-api-key-here"
const SAMPLE_SECRET = "replace-with-your-secret"

// Example usage
const client = new Client({
  apiKey: EXAMPLE_API_KEY
})

// Example SQL (for documentation)
const exampleQuery = "SELECT * FROM users WHERE id = '" + userId + "'"
`,
    language: 'typescript',
    size: 300,
  },
}

/**
 * Configuration files with env vars should be mostly safe
 */
export const configFileFixture: TestFixture = {
  name: 'Config File - Should Not Flag',
  expectFindings: false,
  description: 'Config files using environment variables should be safe',
  file: {
    path: 'src/config/index.ts',
    content: `
// All from environment - SAFE
export const config = {
  database: {
    url: process.env.DATABASE_URL!,
    poolSize: parseInt(process.env.DB_POOL_SIZE || '10'),
  },
  auth: {
    secret: process.env.JWT_SECRET!,
    expiresIn: process.env.JWT_EXPIRES_IN || '7d',
  },
  api: {
    openaiKey: process.env.OPENAI_API_KEY!,
    anthropicKey: process.env.ANTHROPIC_API_KEY!,
  },
}

// Type checking
if (!config.database.url) {
  throw new Error('DATABASE_URL is required')
}
`,
    language: 'typescript',
    size: 500,
  },
}

/**
 * Middleware file that protects routes
 */
export const middlewareFileFixture: TestFixture = {
  name: 'Middleware - Should Detect Auth',
  expectFindings: false,
  description: 'Middleware files should not generate auth warnings',
  file: {
    path: 'middleware.ts',
    content: `
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'

const isPublicRoute = createRouteMatcher([
  '/sign-in(.*)',
  '/sign-up(.*)',
  '/api/webhook(.*)',
  '/',
])

export default clerkMiddleware((auth, request) => {
  if (!isPublicRoute(request)) {
    auth().protect()
  }
})

export const config = {
  matcher: ['/((?!.+\\.[\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'],
}
`,
    language: 'typescript',
    size: 400,
  },
}

/**
 * Routes under /api should NOT be flagged (protected by middleware)
 */
export const protectedApiRouteFixture: TestFixture = {
  name: 'Protected Route - Should Not Flag Missing Auth',
  expectFindings: false,
  description: 'Routes protected by middleware should not be flagged for missing auth',
  file: {
    path: 'app/api/user/settings/route.ts',
    content: `
import { NextResponse } from 'next/server'
import { db } from '@/lib/db'
import { getCurrentUserId } from '@/lib/auth'

// Protected by Clerk middleware - Should NOT flag as missing auth
export async function GET() {
  const userId = await getCurrentUserId()  // Throws if not authenticated

  const settings = await db.settings.findUnique({
    where: { userId }
  })

  return NextResponse.json(settings)
}

export async function PUT(request: Request) {
  const userId = await getCurrentUserId()
  const body = await request.json()

  await db.settings.update({
    where: { userId },
    data: body
  })

  return NextResponse.json({ success: true })
}
`,
    language: 'typescript',
    size: 600,
  },
}

/**
 * Documentation/README files
 */
export const documentationFixture: TestFixture = {
  name: 'Documentation - Should Not Flag',
  expectFindings: false,
  description: 'Documentation files should not be flagged',
  file: {
    path: 'docs/API_GUIDE.md',
    content: `
# API Guide

## Authentication

To authenticate, you need an API key:

\`\`\`typescript
const client = new Client({
  apiKey: "sk-your-api-key-here"
})
\`\`\`

## Example Query

\`\`\`sql
SELECT * FROM users WHERE id = 'user_123'
\`\`\`

## Configuration

Set these environment variables:
- \`API_KEY=your-api-key\`
- \`DATABASE_URL=postgresql://localhost/mydb\`
`,
    language: 'markdown',
    size: 400,
  },
}

/**
 * All false positive fixtures
 */
export const falsePositiveFixtures: TestFixture[] = [
  testFileFixture,
  exampleFileFixture,
  configFileFixture,
  middlewareFileFixture,
  protectedApiRouteFixture,
  documentationFixture,
]
