from datetime import datetime
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field


class PedimentoRectificationOriginBase(BaseModel):
    """Base schema for Pedimento Rectification Origin"""

    pedimento_id: Optional[int] = Field(None, description="Pedimento ID")
    tenant_id: Optional[int] = Field(None, description="Tenant ID")
    original_pedimento_year: Optional[str] = Field(
        None, max_length=2, description="Original pedimento year"
    )
    original_customs_office: Optional[str] = Field(
        None, max_length=3, description="Original customs office"
    )
    original_license: Optional[str] = Field(
        None, max_length=4, description="Original license"
    )
    original_pedimento_number: Optional[str] = Field(
        None, max_length=7, description="Original pedimento number"
    )
    original_pedimento_code: Optional[str] = Field(
        None, max_length=2, description="Original pedimento key"
    )
    original_payment_date: Optional[datetime] = Field(
        None, description="Original payment date"
    )
    total_cash: Optional[int] = Field(None, description="Total cash")
    total_others: Optional[int] = Field(None, description="Total others")
    reason: Optional[str] = Field(None, max_length=255, description="Reason")
    charge_to_client: Optional[int] = Field(None, description="Charge to client")
    use_original_payment_date_for_interest_calc: Optional[int] = Field(
        None, description="Use original payment date for interest calculation"
    )
    manual_calculation: Optional[int] = Field(None, description="Manual calculation")
    original_pedimento_norms: Optional[int] = Field(
        None, description="Original pedimento norms"
    )


class PedimentoRectificationOriginCreate(PedimentoRectificationOriginBase):
    """Schema for creating a new Pedimento Rectification Origin"""

    pass


class PedimentoRectificationOriginUpdate(BaseModel):
    """Schema for updating a Pedimento Rectification Origin"""

    original_pedimento_year: Optional[str] = Field(None, max_length=2)
    original_customs_office: Optional[str] = Field(None, max_length=3)
    original_license: Optional[str] = Field(None, max_length=4)
    original_pedimento_number: Optional[str] = Field(None, max_length=7)
    original_pedimento_code: Optional[str] = Field(None, max_length=2)
    original_payment_date: Optional[datetime] = None
    total_cash: Optional[int] = None
    total_others: Optional[int] = None
    reason: Optional[str] = Field(None, max_length=255)
    charge_to_client: Optional[int] = None
    use_original_payment_date_for_interest_calc: Optional[int] = None
    manual_calculation: Optional[int] = None
    original_pedimento_norms: Optional[int] = None


class PedimentoRectificationOriginResponse(PedimentoRectificationOriginBase):
    """Schema for Pedimento Rectification Origin response"""

    id: int

    model_config = ConfigDict(from_attributes=True)
