/**
 * TypeScript Types for Test Dashboard
 */

export type TestFramework =
  | 'go_test'
  | 'pytest'
  | 'jest'
  | 'playwright'
  | 'bqas_golden'
  | 'bqas_rag'
  | 'bqas_synthetic'

export type TestCategory = 'unit' | 'integration' | 'e2e' | 'bqas' | 'security' | 'performance'

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

export type RunStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled'

export interface TestCase {
  id: string
  name: string
  file_path: string
  line_number?: number
  framework: TestFramework
  category: TestCategory
  duration_ms?: number
  status: TestStatus
  error_message?: string
  output?: string
}

export interface ServiceTestInfo {
  service: string
  display_name: string
  port?: number
  language: string
  total_tests: number
  passed_tests: number
  failed_tests: number
  skipped_tests: number
  pass_rate: number
  coverage_percent?: number
  last_run?: string
  status: TestStatus
}

export interface TestRun {
  id: string
  suite_id: string
  service: string
  started_at: string
  completed_at?: string
  status: RunStatus
  total_tests: number
  passed_tests: number
  failed_tests: number
  skipped_tests: number
  duration_seconds: number
  git_commit?: string
  git_branch?: string
  coverage_percent?: number
  triggered_by: string
  output?: string
  failed_test_ids: string[]
}

export interface TestRegistryStats {
  total_tests: number
  total_passed: number
  total_failed: number
  total_skipped: number
  overall_pass_rate: number
  average_coverage?: number
  services_count: number
  last_full_run?: string
  by_category: Record<string, number>
  by_framework: Record<string, number>
}

export interface RegistryResponse {
  services: ServiceTestInfo[]
  stats: TestRegistryStats
  last_updated: string
}

export interface CoverageData {
  service: string
  display_name: string
  coverage_percent: number
  language: string
}

export interface CoverageResponse {
  services: CoverageData[]
  average_coverage: number
  total_services: number
}

export type TabType = 'overview' | 'unit' | 'integration' | 'bqas' | 'history' | 'backlog' | 'guide'

export type BacklogStatus = 'open' | 'in_progress' | 'fixed' | 'wont_fix' | 'flaky'
export type BacklogPriority = 'critical' | 'high' | 'medium' | 'low'

export interface FailedTest {
  id: string
  name: string
  service: string
  file_path: string
  line_number?: number
  error_message: string
  error_type: string
  suggestion: string
  run_id: string
  last_failed: string
  status: BacklogStatus
}

export interface FailedTestsResponse {
  total_failed: number
  by_service: Record<string, FailedTest[]>
  tests: FailedTest[]
  last_updated: string
}

// Neue PostgreSQL-basierte Backlog-Typen
export interface BacklogItem {
  id: number
  test_name: string
  test_file: string | null
  service: string
  framework: string | null
  error_message: string | null
  error_type: string | null
  first_failed_at: string
  last_failed_at: string
  failure_count: number
  status: BacklogStatus
  priority: BacklogPriority
  assigned_to: string | null
  fix_suggestion: string | null
  notes: string | null
  created_at: string
  updated_at: string
  fixes?: FixAttempt[]
}

export interface FixAttempt {
  id: number
  backlog_id: number
  fix_type: 'manual' | 'auto_claude' | 'auto_script'
  fix_description: string | null
  commit_hash: string | null
  success: boolean
  created_at: string
}

export interface BacklogResponse {
  total: number
  items: BacklogItem[]
  by_service: Record<string, BacklogItem[]>
  filters: {
    status: string | null
    service: string | null
    priority: string | null
  }
  pagination: {
    limit: number
    offset: number
  }
}

export interface TrendDataPoint {
  date: string
  total_tests: number
  passed: number
  failed: number
  runs: number
  pass_rate: number
}

export interface TrendsResponse {
  trends: TrendDataPoint[]
  days: number
  service: string | null
}

export interface Toast {
  id: number
  type: 'success' | 'error' | 'info' | 'loading'
  message: string
}
