import { defineConfig } from 'vitest/config';

const isCoverageRun = process.argv.includes('--coverage');

export default defineConfig({
  test: {
    environment: 'node',
    testTimeout: 15_000,
    retry: 2,
    pool: 'forks',
    // Windows + coverage can race on coverage/.tmp writes across parallel forked files.
    fileParallelism: !isCoverageRun,
    ...(isCoverageRun ? { maxWorkers: 1 } : {}),
    include: ['src/**/*.test.ts'],
    reporters: process.env['CI'] ? ['verbose', 'junit'] : ['default'],
    outputFile: { junit: './test-results/junit.xml' },
    coverage: {
      provider: 'v8',
      reportsDirectory: './coverage',
      reportOnFailure: true,
      reporter: ['text', 'html', 'lcov'],
      include: ['src/**/*.ts'],
      exclude: [
        'src/**/*.test.ts',
        'src/**/index.ts',
        'src/sdk.ts',
        'src/application/ports/**/*.ts',
        'src/infrastructure/adapters/in-memory-*.ts',
        'src/presentation/hooks/**/*.ts',
      ],
      thresholds: {
        statements: 90,
        branches: 80,
        functions: 90,
        lines: 90,
      },
    },
  },
});
