from __future__ import annotations
from typing import List

from pydantic import BaseModel, ConfigDict, EmailStr, Field


class UsuarioCreate(BaseModel):
    identificador: str = Field(min_length=1, max_length=255)
    senha: str = Field(min_length=1, max_length=400)
    ativo: bool = True
    superadmin: bool = False
    auth_id_appwrite: str | None = Field(
        default=None,
        alias="auth-id-appwrite",
        serialization_alias="auth-id-appwrite",
        min_length=1,
        max_length=255,
    )
    nome: str | None = Field(default=None, min_length=1, max_length=255)
    email: EmailStr | None = Field(default=None)
    telefone: str | None = Field(default=None, min_length=10, max_length=11)
    nivel: str | None = Field(default=None, min_length=1, max_length=100)
    registro_completo: bool = Field(
        default=False,
        alias="registro-completo",
        serialization_alias="registro-completo",
    )
    enderecos: List[str] = Field(default_factory=list)
    empresas_dados: List[str] = Field(
        default_factory=list,
        alias="empresasDados",
        serialization_alias="empresasDados",
    )
    nome_social: str | None = Field(
        default=None,
        alias="nome-social",
        serialization_alias="nome-social",
        min_length=1,
        max_length=255,
    )
    cpf: str | None = Field(default=None, pattern=r"^\d{11}$")

    model_config = ConfigDict(populate_by_name=True)


class UsuarioUpdate(BaseModel):
    identificador: str | None = Field(default=None, min_length=1, max_length=255)
    senha: str | None = Field(default=None, min_length=1, max_length=400)
    ativo: bool | None = None
    superadmin: bool | None = None
    auth_id_appwrite: str | None = Field(
        default=None,
        alias="auth-id-appwrite",
        serialization_alias="auth-id-appwrite",
        min_length=1,
        max_length=255,
    )
    nome: str | None = Field(default=None, min_length=1, max_length=255)
    email: EmailStr | None = Field(default=None)
    telefone: str | None = Field(default=None, min_length=10, max_length=11)
    nivel: str | None = Field(default=None, min_length=1, max_length=100)
    registro_completo: bool | None = Field(
        default=None,
        alias="registro-completo",
        serialization_alias="registro-completo",
    )
    enderecos: List[str] | None = Field(default=None)
    empresas_dados: List[str] | None = Field(
        default=None,
        alias="empresasDados",
        serialization_alias="empresasDados",
    )
    nome_social: str | None = Field(
        default=None,
        alias="nome-social",
        serialization_alias="nome-social",
        min_length=1,
        max_length=255,
    )
    cpf: str | None = Field(default=None, pattern=r"^\d{11}$")

    model_config = ConfigDict(populate_by_name=True)


class UsuarioOut(BaseModel):
    id: str
    identificador: str
    ativo: bool
    superadmin: bool
    auth_id_appwrite: str | None = Field(
        default=None,
        alias="auth-id-appwrite",
        serialization_alias="auth-id-appwrite",
    )
    nome: str | None = None
    email: EmailStr | None = None
    telefone: str | None = None
    nivel: str | None = None
    registro_completo: bool = Field(
        default=False,
        alias="registro-completo",
        serialization_alias="registro-completo",
    )
    enderecos: List[str] = Field(default_factory=list)
    empresas_dados: List[str] = Field(
        default_factory=list,
        alias="empresasDados",
        serialization_alias="empresasDados",
    )
    nome_social: str | None = Field(
        default=None,
        alias="nome-social",
        serialization_alias="nome-social",
    )
    cpf: str | None = None
    createdAt: str
    updatedAt: str

    model_config = ConfigDict(from_attributes=True, populate_by_name=True)
