from pydantic import BaseModel, Field
from typing import Optional, List, Literal


class CustomAssignment(BaseModel):
    material_path: str
    start: float           # 音频时间轴起点
    end: float             # 音频时间轴终点
    source_start: float = 0.0  # 源视频截取起点
    source_end: Optional[float] = None  # 源视频截取终点（可选）


class GenerateRequest(BaseModel):
    text: str
    voice: str = "zh-CN-YunxiNeural"
    material_path: str
    material_paths: Optional[List[str]] = None
    tts_mode: str = "edgetts"
    ref_audio_id: Optional[str] = None
    ref_text: Optional[str] = None
    language: str = "zh-CN"
    generated_audio_id: Optional[str] = None  # 预生成配音 ID（存在时跳过内联 TTS）
    title: Optional[str] = None
    title_display_mode: Literal["short", "persistent"] = "short"
    title_duration: float = 4.0
    enable_subtitles: bool = True
    subtitle_style_id: Optional[str] = None
    title_style_id: Optional[str] = None
    secondary_title: Optional[str] = None
    secondary_title_style_id: Optional[str] = None
    secondary_title_font_size: Optional[int] = None
    secondary_title_top_margin: Optional[int] = None
    subtitle_font_size: Optional[int] = None
    title_font_size: Optional[int] = None
    title_top_margin: Optional[int] = None
    subtitle_bottom_margin: Optional[int] = None
    bgm_id: Optional[str] = None
    bgm_volume: Optional[float] = 0.2
    custom_assignments: Optional[List[CustomAssignment]] = None
    output_aspect_ratio: Literal["9:16", "16:9"] = "9:16"
    lipsync_model: Literal["default", "fast", "advanced"] = "default"


class VoicePreviewRequest(BaseModel):
    voice: str
    text: str = Field(..., min_length=1, max_length=120)
