from __future__ import annotations

from typing import List

from pydantic import BaseModel, ConfigDict, Field


class UsuarioPerfilBase(BaseModel):
    codigo: str = Field(
        min_length=1,
        max_length=50,
        description="Código único do perfil",
        examples=["ADM"],
    )
    nome: str = Field(
        min_length=1,
        max_length=150,
        description="Nome legível do perfil",
        examples=["Administrador"],
    )


class UsuarioPerfilCreate(UsuarioPerfilBase):
    """Payload para criação de perfis de usuário."""


class UsuarioPerfilUpdate(BaseModel):
    codigo: str | None = Field(
        default=None,
        min_length=1,
        max_length=50,
        description="Código único do perfil",
    )
    nome: str | None = Field(
        default=None,
        min_length=1,
        max_length=150,
        description="Nome legível do perfil",
    )


class UsuarioPerfilOut(BaseModel):
    id: str
    codigo: str
    nome: str
    createdAt: str
    updatedAt: str

    model_config = ConfigDict(
        from_attributes=True,
        json_schema_extra={
            "example": {
                "id": "perfil_admin",
                "codigo": "ADM",
                "nome": "Administrador",
                "createdAt": "2025-01-01T12:00:00.000Z",
                "updatedAt": "2025-01-01T12:00:00.000Z",
            }
        },
    )


class PaginatedUsuariosPerfil(BaseModel):
    items: List[UsuarioPerfilOut]
    total: int

    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "items": [
                    {
                        "id": "perfil_admin",
                        "codigo": "ADM",
                        "nome": "Administrador",
                        "createdAt": "2025-01-01T12:00:00.000Z",
                        "updatedAt": "2025-01-01T12:00:00.000Z",
                    }
                ],
                "total": 1,
            }
        }
    )
