/**
 * Main Vitest Configuration
 *
 * Runs ALL tests when using `pnpm test` or `pnpm test:coverage`.
 * For targeted test runs, use the group-specific configs:
 *
 *   pnpm test:unit      - Pure functions (utils, parsers, schemas)
 *   pnpm test:services  - Business logic (services, jobs)
 *   pnpm test:routes    - API endpoints (routes with mocked DB)
 *   pnpm test:security  - Auth/authz behavior tests
 *
 * Integration tests use a separate config:
 *   pnpm test:integration - Real DB tests (vitest.integration.config.ts)
 */

import { defineConfig, mergeConfig } from 'vitest/config';
import { sharedConfig } from './vitest.shared.js';

export default mergeConfig(
  sharedConfig,
  defineConfig({
    test: {
      // Run all unit + security tests (excludes integration)
      include: ['src/**/*.test.ts'],
      exclude: ['**/node_modules/**', '**/dist/**', '**/*.integration.test.ts'],
      coverage: {
        provider: 'v8',
        reporter: ['text', 'json', 'json-summary', 'html', 'lcov'],
        reportsDirectory: './coverage',
        include: [
          'src/services/**/*.ts',
          'src/routes/**/*.ts',
          'src/jobs/**/*.ts',
          'src/utils/**/*.ts',
        ],
        exclude: [
          '**/*.test.ts',
          '**/test/**',
          // Type-only files with no executable code
          '**/types.ts',
          // Index files that only register routes (no business logic)
          '**/routes/**/index.ts',
          '**/routes/auth/index.ts',
          '**/routes/stats/index.ts',
          '**/routes/users/index.ts',
          // HTTP client wrappers tested via integration tests
          '**/services/mediaServer/plex/client.ts',
          '**/services/mediaServer/plex/eventSource.ts',
          '**/services/mediaServer/jellyfin/client.ts',
          '**/services/mediaServer/emby/client.ts',
        ],
        thresholds: {
          statements: 42,
          branches: 36,
          functions: 48,
          lines: 42,
        },
      },
    },
  })
);
