export interface TestSuite {
  id: string;
  name: string;
  path: string;
  tests: TestCase[];
  status: TestStatus;
  duration?: number;
  timestamp: string;
}

export interface TestCase {
  id: string;
  name: string;
  suite: string;
  status: TestStatus;
  duration?: number;
  error?: TestError;
  assertions?: number;
  skipped?: boolean;
  tags?: string[];
}

export type TestStatus = 'pending' | 'running' | 'passed' | 'failed' | 'skipped';

export interface TestError {
  message: string;
  stack?: string;
  expected?: any;
  actual?: any;
  type?: string;
}

export interface TestResult {
  id: string;
  timestamp: string;
  projectId: string;
  branch?: string;
  commit?: string;
  framework: TestFramework;
  suites: TestSuite[];
  summary: TestSummary;
  coverage?: CoverageReport;
  duration: number;
  command: string;
  tags?: string[];
}

export interface TestSummary {
  total: number;
  passed: number;
  failed: number;
  skipped: number;
  pending: number;
  duration: number;
  successRate: number;
}

export interface CoverageReport {
  lines: CoverageMetric;
  statements: CoverageMetric;
  functions: CoverageMetric;
  branches: CoverageMetric;
  files: FileCoverage[];
}

export interface CoverageMetric {
  total: number;
  covered: number;
  skipped: number;
  percentage: number;
}

export interface FileCoverage {
  path: string;
  lines: CoverageMetric;
  statements: CoverageMetric;
  functions: CoverageMetric;
  branches: CoverageMetric;
  uncoveredLines?: number[];
}

export type TestFramework = 'jest' | 'mocha' | 'vitest' | 'pytest' | 'rspec' | 'unknown';

export interface TestRunOptions {
  files?: string[];
  pattern?: string;
  watch?: boolean;
  coverage?: boolean;
  bail?: boolean;
  verbose?: boolean;
  updateSnapshots?: boolean;
  parallel?: boolean;
  maxWorkers?: number;
  timeout?: number;
  grep?: string;
  tags?: string[];
}

export interface TestWatcher {
  id: string;
  patterns: string[];
  command: string;
  active: boolean;
  lastRun?: TestResult;
  autoRerun: boolean;
  debounceMs: number;
}

export interface TestTrend {
  metric: 'successRate' | 'duration' | 'coverage' | 'testCount';
  values: TimeSeriesData[];
  trend: 'improving' | 'stable' | 'degrading';
  changePercentage: number;
}

export interface TimeSeriesData {
  timestamp: string;
  value: number;
  label?: string;
}

export interface TestComparison {
  baseline: TestResult;
  current: TestResult;
  improvements: string[];
  regressions: string[];
  newTests: string[];
  removedTests: string[];
  coverageChange: CoverageChange;
}

export interface CoverageChange {
  lines: number;
  statements: number;
  functions: number;
  branches: number;
}

export interface TestConfiguration {
  framework: TestFramework;
  command: string;
  configFile?: string;
  testMatch?: string[];
  coverageThreshold?: {
    global?: CoverageThreshold;
    [path: string]: CoverageThreshold | undefined;
  };
  setupFiles?: string[];
  testEnvironment?: string;
}

export interface CoverageThreshold {
  lines?: number;
  statements?: number;
  functions?: number;
  branches?: number;
}

export interface TestHistory {
  projectId: string;
  results: TestResult[];
  baseline?: TestResult;
  trends: TestTrend[];
  lastUpdated: string;
}

export interface TestRecommendation {
  type: 'add-tests' | 'fix-flaky' | 'improve-coverage' | 'optimize-performance' | 'update-assertions';
  title: string;
  description: string;
  priority: 'high' | 'medium' | 'low';
  affectedTests?: string[];
  suggestedAction?: string;
}

export interface FlakyTest {
  testId: string;
  name: string;
  suite: string;
  failureRate: number;
  recentResults: TestStatus[];
  lastFailed: string;
  errorPatterns: string[];
  testName?: string;
  suiteName?: string;
  firstSeen?: string;
  lastSeen?: string;
  failures?: number;
  passes?: number;
  totalRuns?: number;
  recentRuns?: Array<{ passed: boolean; timestamp: string }>;
}

export interface CoverageData {
  // Legacy type for backward compatibility
  [key: string]: any;
}

export interface TestBaseline {
  // Legacy type for backward compatibility
  [key: string]: any;
}