"""Request, response, and patch schemas for the Article domain."""
from __future__ import annotations

from datetime import datetime

from repo_core.base.schemas import (
    BaseRequestSchema,
    BaseResponseSchema,
    BasePatchSchema,
)


class CreateArticleRequest(BaseRequestSchema):
    """Validated payload for creating a new article.

    Usage::

        payload = CreateArticleRequest(title="Hello", body="World")
    """

    title: str
    body: str
    tags: list[str] = []


class PatchArticleRequest(BasePatchSchema):
    """Partial update payload for an existing article.

    Only fields that are explicitly provided are included in the patch dict::

        patch = PatchArticleRequest(title="New title")
        update_fields = patch.to_patch_dict()  # {"title": "New title"}
    """

    title: str | None = None
    body: str | None = None
    published: bool | None = None


class ArticleResponse(BaseResponseSchema):
    """Serialised article returned to API callers.

    Accepts ORM objects directly::

        response = ArticleResponse.model_validate(orm_article)
        data = response.to_dict()
    """

    id: int
    title: str
    body: str
    published: bool
    created_at: datetime | None = None
    updated_at: datetime | None = None
