import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  test: {
    environment: 'happy-dom',
    include: ['tests/unit/**/*.{test,spec}.ts'],
    globals: true,
    setupFiles: ['./vitest.setup.ts'],
    coverage: {
      provider: 'v8',
      reporter: ['text', 'text-summary', 'html', 'lcov'],
      reportsDirectory: './coverage',
      include: ['src/**/*.ts', 'src/**/*.vue'],
      exclude: [
        'src/main.ts',
        'src/env.d.ts',
        'src/**/*.d.ts',
        'src/types/**',
        // Exclude demo and test views that are not core functionality
        'src/views/demo/**',
        'src/views/test/**',
        'src/views/cc/**',
        'src/views/monitor/**',
        'src/views/stream/**',
        'src/views/camera/channel.vue',
        'src/views/camera/stream-test.vue',
        'src/views/camera/video.vue',
        // Exclude layout and router (tested via E2E)
        'src/layout/**',
        'src/router/**',
        // Exclude complex components/composables that are hard to unit test
        'src/components/VideoPlayer.vue',
        'src/components/monitor/**',
        'src/components/ThemeSettings.vue',
        'src/components/PtzController.vue',
        'src/components/HelloWorld.vue',
        'src/composables/**',
        // Exclude complex API modules with external dependencies
        'src/api/ptz.ts',
        'src/api/stream.ts',
        'src/api/cloudflare-stream.ts',
        'src/store/stream.ts',
        'src/store/index.ts',
        'src/utils/request.ts'
      ],
      // Coverage thresholds - target 60%
      thresholds: {
        statements: 60,
        branches: 50,
        functions: 50,
        lines: 60
      }
    }
  }
})
