"""
分镜（Segment）统一 Schema
==========================

业务层唯一分镜模型，取代以下历史重复定义：
- ScriptShot（script.py）
- ShotData（api/v1/video.py）
- ShotUnit（scheduler/models.py）
"""

from typing import Literal

from pydantic import BaseModel, Field

from app.schemas.enums import SegmentStatus


class Segment(BaseModel):
    """视频分镜/镜头定义

    术语说明：
    - segment: 分镜
    - empty_shot: 空镜
    """

    id: str = Field(..., description="分镜ID")
    type: Literal["segment", "empty_shot"] = Field(
        default="segment", description="分镜类型: segment(分镜) 或 empty_shot(空镜)"
    )
    scene: str = Field(default="", description="场景描述/画面描述")
    voiceover: str = Field(default="", description="配音文本（空镜可为空）")
    duration: int | None = Field(default=None, description="时长（秒）")
    voice_id: str | None = Field(default=None, description="音色ID（空镜时使用）")
    status: SegmentStatus = Field(default=SegmentStatus.PENDING)
    provider_task_id: str | None = Field(
        default=None, description="供应商任务ID"
    )
    video_url: str | None = Field(default=None, description="生成后的视频URL")
    local_path: str | None = Field(default=None, description="本地视频路径")
    qiniu_url: str | None = Field(default=None, description="七牛云URL")
    error_message: str | None = Field(default=None, description="错误信息")
    stage: str | None = Field(
        default=None, description="内部处理阶段（如 image_generating / video_processing）"
    )
    image_task_id: str | None = Field(default=None, description="空镜文生图任务ID（内部使用）")
    query_fail_count: int = Field(default=0, description="查询失败计数")
