"""User schemas.

When ``use_auth == "yes"`` the auth-related schemas (``UserCreate``,
``UserLogin``, ``Token``) are added; ``UserResponse`` and ``UserInput``
are always present.
"""

from __future__ import annotations

from pydantic import BaseModel, EmailStr, Field


class UserInput(BaseModel):
    """Input payload for creating a user."""

    username: str = Field(min_length=3, max_length=64)
    email: EmailStr


class UserResponse(BaseModel):
    """Public user representation (never leaks the password)."""

    id: int
    username: str
    email: EmailStr


{% if cookiecutter.use_auth == "yes" and cookiecutter.use_db == "yes" %}
class UserCreate(BaseModel):
    """Registration payload — username, email, plain password."""

    username: str = Field(min_length=3, max_length=64)
    email: EmailStr
    password: str = Field(min_length=8, max_length=128)


class UserLogin(BaseModel):
    """Login payload — username + plain password."""

    username: str
    password: str


class Token(BaseModel):
    """JWT response envelope."""

    access_token: str
    token_type: str = "bearer"
{% endif %}