import swc from 'unplugin-swc';
import path from 'path';
import { defineConfig } from 'vitest/config';

export default defineConfig({
  plugins: [
    swc.vite({
      module: { type: 'es6' },
      jsc: {
        parser: {
          syntax: 'typescript',
          decorators: true,
        },
        transform: {
          legacyDecorator: true,
          decoratorMetadata: true,
        },
      },
    }),
  ],
  test: {
    globals: true,
    environment: 'node',
    testTimeout: 30000,
    include: ['src/**/*.spec.ts', 'test/**/*.spec.ts'],
    exclude: ['**/*.e2e-spec.ts', 'node_modules', 'dist'],
    setupFiles: ['./test/setup.ts'],
    coverage: {
      provider: 'v8',
      reporter: ['text', 'json', 'html'],
      include: [
        'src/acquisition/**/*.service.ts',
        'src/engagement/**/*.service.ts',
        'src/audience/**/*.service.ts',
        'src/sessions/**/*.service.ts',
        'src/segments/**/*.service.ts',
        'src/trends/**/*.service.ts',
        'src/funnels/**/*.service.ts',
        'src/cohorts/**/*.service.ts',
      ],
      exclude: [
        'node_modules/',
        'dist/',
        '**/*.spec.ts',
        '**/*.e2e-spec.ts',
        '**/main.ts',
        '**/index.ts',
        '**/*.dto.ts',
        '**/*.module.ts',
        '**/*.controller.ts',
        '**/*.entity.ts',
        'test/**',
        'vitest*.config.ts',
        'scripts/**',
      ],
      thresholds: {
        statements: 80,
        branches: 80,
        functions: 80,
        lines: 80,
      },
    },
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@test': path.resolve(__dirname, './test'),
    },
  },
});
