from datetime import date as DateType from pydantic import BaseModel, ConfigDict, field_validator from ..services.path import encode_path class VideoOut(BaseModel): model_config = ConfigDict(from_attributes=True) id: int path: str preview_path: str channel_id: int title: str | None = None date: DateType | None = None channel_name: str | None = None @field_validator("path", "preview_path", mode="before") @classmethod def encode_urls(cls, v): return encode_path(v) @field_validator("path", mode="after") @classmethod def add_yt(cls, v: str) -> str: if not v: return v clean_v = v.lstrip('/') if clean_v.startswith('yt/'): return f"/{clean_v}" return f"yt/{clean_v}" class VideoDetailOut(BaseModel): model_config = ConfigDict(from_attributes=True) id: int path: str preview_path: str title: str | None = None date: DateType | None = None channel_id: int channel_name: str | None = None @field_validator("path", "preview_path", mode="before") @classmethod def encode_urls(cls, v): return encode_path(v) @field_validator("path", mode="after") @classmethod def add_yt(cls, v: str) -> str: if not v: return v clean_v = v.lstrip('/') if clean_v.startswith('yt/'): return f"/{clean_v}" return f"yt/{clean_v}" class VideosResponse(BaseModel): videos: list[VideoOut] page_inc: str page_dec: str