from datetime import datetime
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field


class PedimentoValidationBase(BaseModel):
    """Base schema for Pedimento Validation"""

    pedimento_id: Optional[int] = Field(None, description="Pedimento ID")
    tenant_id: Optional[int] = Field(None, description="Tenant ID")
    validator: Optional[str] = Field(None, max_length=3, description="Validator")
    validation_ack: Optional[str] = Field(
        None, max_length=8, description="Validation acknowledgment"
    )
    pre_ack: Optional[str] = Field(None, max_length=8, description="Pre-acknowledgment")
    line_signature: Optional[str] = Field(
        None, max_length=50, description="Line signature"
    )
    electronic_signature: Optional[str] = Field(
        None, max_length=999, description="Electronic signature"
    )
    certificate_number: Optional[str] = Field(
        None, max_length=99, description="Certificate number"
    )
    validator_id: Optional[int] = Field(None, description="Validator ID")
    responsible_id: Optional[int] = Field(None, description="Responsible ID")


class PedimentoValidationCreate(BaseModel):
    """Schema for creating a new Pedimento Validation - pedimento_id and tenant_id are set by backend"""

    validator: Optional[str] = Field(None, max_length=3, description="Validator")
    validation_ack: Optional[str] = Field(None, max_length=8, description="Validation acknowledgment")
    pre_ack: Optional[str] = Field(None, max_length=8, description="Previous acknowledgment")
    line_signature: Optional[str] = Field(None, max_length=50, description="Line signature")
    electronic_signature: Optional[str] = Field(None, max_length=999, description="Electronic signature")
    certificate_number: Optional[str] = Field(None, max_length=99, description="Certificate number")
    validator_id: Optional[int] = Field(None, description="Validator ID")
    responsible_id: Optional[int] = Field(None, description="Responsible ID")


class PedimentoValidationUpdate(BaseModel):
    """Schema for updating a Pedimento Validation"""

    validator: Optional[str] = Field(None, max_length=3)
    validation_ack: Optional[str] = Field(None, max_length=8)
    pre_ack: Optional[str] = Field(None, max_length=8)
    line_signature: Optional[str] = Field(None, max_length=50)
    electronic_signature: Optional[str] = Field(None, max_length=999)
    certificate_number: Optional[str] = Field(None, max_length=99)
    validator_id: Optional[int] = None
    responsible_id: Optional[int] = None


class PedimentoValidationResponse(PedimentoValidationBase):
    """Schema for Pedimento Validation response"""

    id: int
    created_at: datetime

    model_config = ConfigDict(from_attributes=True)
