from datetime import datetime
from typing import Literal

from pydantic import BaseModel, Field, HttpUrl


class MediaInput(BaseModel):
    type: Literal["image", "video"] = "image"
    url: str = Field(min_length=1, max_length=2000)
    alt: str = Field(default="", max_length=500)
    width: int | None = Field(default=None, ge=1)
    height: int | None = Field(default=None, ge=1)
    sort_order: int = Field(default=0, ge=0)


class ArticleUpsert(BaseModel):
    external_id: str = Field(min_length=1, max_length=160)
    slug: str | None = Field(default=None, max_length=220)
    title: str = Field(min_length=5, max_length=300)
    lead: str = Field(default="", max_length=1000)
    body: str = Field(min_length=20, max_length=50000)
    category_name: str = Field(min_length=1, max_length=120)
    category_tag: str = Field(min_length=1, max_length=120)
    producer_name: str = Field(min_length=1, max_length=200)
    producer_tag: str = Field(min_length=1, max_length=160)
    source_url: HttpUrl | None = None
    seo_title: str | None = Field(default=None, max_length=300)
    seo_description: str | None = Field(default=None, max_length=500)
    status: Literal["draft", "published"] = "published"
    published_at: datetime | None = None
    media: list[MediaInput] = Field(default_factory=list, max_length=20)
