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

from datetime import datetime

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


class CreateEntityRequest(BaseRequestSchema):
    """Validated payload for creating a new entity.

    Usage::

        payload = CreateEntityRequest(name="Acme Corp", description="A company")
    """

    name: str
    description: str = ""
    active: bool = True


class PatchEntityRequest(BasePatchSchema):
    """Partial update payload for an existing entity.

    Only explicitly provided fields are included in ``to_patch_dict()``::

        patch = PatchEntityRequest(active=False)
        update_fields = patch.to_patch_dict()  # {"active": False}
    """

    name: str | None = None
    description: str | None = None
    active: bool | None = None


class EntityResponse(BaseResponseSchema):
    """Serialised entity returned to API callers.

    Accepts ORM objects directly::

        response = EntityResponse.model_validate(orm_entity)
        data = response.to_dict()
    """

    id: str
    name: str
    description: str
    active: bool
    created_at: datetime | None = None
    updated_at: datetime | None = None
