"""Pydantic models for Whisper Scribe."""

from pydantic import BaseModel
from enum import Enum
from typing import Optional, List
from datetime import datetime


class JobStatus(str, Enum):
    """Status of a transcription job."""
    PENDING = "pending"
    FETCHING_INFO = "fetching_info"
    DOWNLOADING = "downloading"
    CONVERTING = "converting"
    TRANSCRIBING = "transcribing"
    SAVING = "saving"
    COMPLETE = "complete"
    ERROR = "error"


class ExportFormat(str, Enum):
    """Available export formats."""
    TXT = "txt"
    SRT = "srt"
    VTT = "vtt"
    DOCX = "docx"


# Request/Response Models
class VideoPreviewRequest(BaseModel):
    url: str


class VideoPreview(BaseModel):
    url: str
    video_id: str
    title: str
    thumbnail: str
    duration: str
    channel: str


class TranscribeRequest(BaseModel):
    url: str


class QueueRequest(BaseModel):
    urls: List[str]


class TranscribeResponse(BaseModel):
    job_id: str
    status: JobStatus


class StatusResponse(BaseModel):
    status: JobStatus
    progress: int = 0
    message: Optional[str] = None
    stage: Optional[str] = None


class ResultResponse(BaseModel):
    text: str
    title: str
    file_path: Optional[str] = None


class HistoryItem(BaseModel):
    id: str
    title: str
    url: str
    created_at: str
    file_path: str
    duration: Optional[str] = None
    thumbnail: Optional[str] = None


class HistoryResponse(BaseModel):
    items: List[HistoryItem]
    total: int


class ExportRequest(BaseModel):
    format: ExportFormat


class QueueStatusResponse(BaseModel):
    queue: List[dict]
    current_job: Optional[str] = None
    total: int
    completed: int


class SettingsRequest(BaseModel):
    openai_api_key: Optional[str] = None
    output_directory: Optional[str] = None


class SettingsResponse(BaseModel):
    openai_api_key_set: bool
    output_directory: str


class ValidateKeyResponse(BaseModel):
    valid: bool
    message: str
