import api from './api';

/** One candidate and whatever became of it. `track_id` is null until acquired. */
export interface DiscoveryRow {
  id: string;
  source: string;
  status: string;
  title: string | null;
  artist_credit: { name?: string; artist_id?: string }[] | null;
  notes: { acquisition?: { query?: string; url?: string }; album?: string; seed_artist?: string; seed_title?: string } | null;
  first_seen_at: string;
  acquired_at: string | null;
  last_error: string | null;
  acquisition_attempts: number;
  track_id: string | null;
  track_title: string | null;
  track_artist: string | null;
  probation_status: 'probation' | 'retained' | 'retired' | null;
  probation_entered_at: string | null;
  completed_plays: number | null;
  quick_skips: number | null;
}

export interface DiscoverySourceSummary {
  source: string;
  candidates: number;
  probation: number;
  retained: number;
  retired: number;
  stalled: number;
}

export const discoveryService = {
  // GET /api/discovery/overview -> every candidate plus per-source totals
  async overview(): Promise<{ rows: DiscoveryRow[]; summary: DiscoverySourceSummary[] }> {
    const res = await api.get<{ rows: DiscoveryRow[]; summary: DiscoverySourceSummary[] }>(
      '/discovery/overview'
    );
    return res.data;
  },
};
