from datetime import datetime from typing import Optional from uuid import UUID from pydantic import BaseModel, ConfigDict, Field class PriorityBase(BaseModel): """Base Pydantic model for priorities""" id: int description: str model_config = ConfigDict(from_attributes=True) class PriorityCreate(PriorityBase): """Pydantic model for creating priorities""" pass class PriorityResponse(PriorityBase): """Pydantic model for priority responses""" pass class ChannelURLCreate(BaseModel): """Pydantic model for creating channel URLs""" url: str priority_id: int = Field( default=100, ge=100, le=300 ) # Default to High, validate range class ChannelURLBase(ChannelURLCreate): """Base Pydantic model for channel URL responses""" id: UUID in_use: bool created_at: datetime updated_at: datetime priority_id: int model_config = ConfigDict(from_attributes=True) class ChannelURLResponse(ChannelURLBase): """Pydantic model for channel URL responses""" pass # New Group Schemas class GroupCreate(BaseModel): """Pydantic model for creating groups""" name: str sort_order: int = Field(default=0, ge=0) class GroupUpdate(BaseModel): """Pydantic model for updating groups""" name: Optional[str] = None sort_order: Optional[int] = Field(None, ge=0) class GroupResponse(BaseModel): """Pydantic model for group responses""" id: UUID name: str sort_order: int created_at: datetime updated_at: datetime model_config = ConfigDict(from_attributes=True) class GroupSortUpdate(BaseModel): """Pydantic model for updating a single group's sort order""" sort_order: int = Field(ge=0) class GroupBulkSort(BaseModel): """Pydantic model for bulk updating group sort orders""" groups: list[dict] = Field( description="List of dicts with group_id and new sort_order", json_schema_extra={"example": [{"group_id": "uuid", "sort_order": 1}]}, ) class ChannelCreate(BaseModel): """Pydantic model for creating channels""" urls: list[ChannelURLCreate] # List of URL objects with priority name: str group_id: UUID tvg_id: str tvg_logo: str tvg_name: str class ChannelURLUpdate(BaseModel): """Pydantic model for updating channel URLs""" url: Optional[str] = None in_use: Optional[bool] = None priority_id: Optional[int] = Field(default=None, ge=100, le=300) class ChannelUpdate(BaseModel): """Pydantic model for updating channels (all fields optional)""" name: Optional[str] = Field(None, min_length=1) group_id: Optional[UUID] = None tvg_id: Optional[str] = Field(None, min_length=1) tvg_logo: Optional[str] = None tvg_name: Optional[str] = Field(None, min_length=1) class ChannelResponse(BaseModel): """Pydantic model for channel responses""" id: UUID name: str group_id: UUID tvg_id: str tvg_logo: str tvg_name: str urls: list[ChannelURLResponse] # List of URL objects without channel_id created_at: datetime updated_at: datetime model_config = ConfigDict(from_attributes=True)