/**
 * TypeScript type definitions for Audio Classifier
 */

export interface Track {
  id: string
  filepath: string
  filename: string
  duration_seconds: number
  file_size_bytes: number
  format: string
  analyzed_at: string

  features: {
    tempo_bpm: number
    key: string
    time_signature: string
    energy: number
    danceability: number
    valence: number
    loudness_lufs: number
    spectral_centroid: number
    zero_crossing_rate: number
  }

  classification: {
    genre: {
      primary: string
      secondary: string[]
      confidence: number
    }
    mood: {
      primary: string
      secondary: string[]
      arousal: number
      valence: number
    }
    instruments: string[]
    vocals: {
      present: boolean | null
      gender: string | null
    }
  }

  embedding: {
    model: string | null
    dimension: number | null
  }

  metadata: Record<string, any>
}

export interface FilterParams {
  genre?: string
  mood?: string
  bpm_min?: number
  bpm_max?: number
  energy_min?: number
  energy_max?: number
  has_vocals?: boolean
  key?: string
  instrument?: string
  tempo_range?: 'slow' | 'medium' | 'fast' // Lent (<100), Moyen (100-140), Rapide (>140)
  sort_by?: 'analyzed_at' | 'tempo_bpm' | 'duration_seconds' | 'filename' | 'energy'
  sort_desc?: boolean
}

export interface TracksResponse {
  tracks: Track[]
  total: number
  skip: number
  limit: number
}

export interface SearchResponse {
  query: string
  tracks: Track[]
  total: number
}

export interface SimilarTracksResponse {
  reference_track_id: string
  similar_tracks: Track[]
  total: number
}

export interface JobStatus {
  job_id: string
  status: 'pending' | 'running' | 'completed' | 'failed'
  progress: number
  total: number
  current_file: string | null
  errors: Array<{ file?: string; error: string }>
  saved_count?: number
}

export interface AnalyzeFolderRequest {
  path: string
  recursive: boolean
}

export interface WaveformData {
  peaks: number[]
  duration: number
  num_peaks: number
}

export interface Stats {
  total_tracks: number
  genres: Array<{ genre: string; count: number }>
  moods: Array<{ mood: string; count: number }>
  average_bpm: number
  total_duration_hours: number
}
