import { request, BASE } from "./client";

// ── Types ────────────────────────────────────────────────────────────────────

export interface VideoDetail {
  id: string;
  filename: string;
  file_path: string;
  duration_seconds: number | null;
  content_type: string;
  creator_id: string;
  creator_name: string;
  creator_slug: string;
  video_url: string | null;
  processing_status: string;
  created_at: string;
  updated_at: string;
}

export interface TranscriptSegment {
  id: string;
  source_video_id: string;
  start_time: number;
  end_time: number;
  text: string;
  segment_index: number;
  topic_label: string | null;
}

export interface TranscriptResponse {
  video_id: string;
  segments: TranscriptSegment[];
  total: number;
}

// ── API functions ────────────────────────────────────────────────────────────

export function fetchVideo(id: string): Promise<VideoDetail> {
  return request<VideoDetail>(`${BASE}/videos/${encodeURIComponent(id)}`);
}

export function fetchTranscript(videoId: string): Promise<TranscriptResponse> {
  return request<TranscriptResponse>(
    `${BASE}/videos/${encodeURIComponent(videoId)}/transcript`,
  );
}
