"""
DTOs (Data Transfer Objects) para módulo de catálogos de errores
"""

from typing import Optional, List

from pydantic import BaseModel, Field


# ============ ERROR CLASSIFICATION DTOS ============
class ErrorClassificationCreateDTO(BaseModel):
    """DTO para crear una clasificación de error"""

    code: str = Field(..., max_length=100, description="Classification code")
    level: Optional[str] = Field(None, max_length=3, description="Level")

    class Config:
        from_attributes = True


class ErrorClassificationUpdateDTO(BaseModel):
    """DTO para actualizar una clasificación de error"""

    level: Optional[str] = Field(None, max_length=3, description="Level")

    class Config:
        from_attributes = True


class ErrorClassificationResponseDTO(BaseModel):
    """DTO para responder con datos de una clasificación de error"""

    id: int
    code: str
    level: Optional[str] = None

    class Config:
        from_attributes = True


class ErrorClassificationDetailResponseDTO(BaseModel):
    """DTO detallado para responder con datos de una clasificación y sus errores"""

    id: int
    code: str
    level: Optional[str] = None
    errors: List["ErrorCatalogResponseDTO"] = []

    class Config:
        from_attributes = True


# ============ ERROR CATALOG DTOS ============
class ErrorCatalogCreateDTO(BaseModel):
    """DTO para crear un error en el catálogo"""

    code: str = Field(..., max_length=15, description="Error code")
    description: Optional[str] = Field(
        None, max_length=255, description="Error description"
    )
    classification_id: Optional[int] = Field(
        None, description="Classification ID"
    )

    class Config:
        from_attributes = True


class ErrorCatalogUpdateDTO(BaseModel):
    """DTO para actualizar un error en el catálogo"""

    description: Optional[str] = Field(
        None, max_length=255, description="Error description"
    )
    classification_id: Optional[int] = Field(
        None, description="Classification ID"
    )

    class Config:
        from_attributes = True


class ErrorCatalogResponseDTO(BaseModel):
    """DTO para responder con datos de un error en el catálogo"""

    id: int
    code: str
    description: Optional[str] = None
    classification_id: Optional[int] = None

    class Config:
        from_attributes = True


class ErrorCatalogDetailResponseDTO(BaseModel):
    """DTO detallado para responder con datos de un error y su clasificación"""

    id: int
    code: str
    description: Optional[str] = None
    classification_id: Optional[int] = None
    classification: Optional[ErrorClassificationResponseDTO] = None

    class Config:
        from_attributes = True
