from datetime import datetime
from decimal import Decimal
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field


class PedimentoConfigParametersBase(BaseModel):
    """Base schema for Pedimento Config Parameters"""

    pedimento_id: Optional[int] = Field(None, description="Pedimento ID")
    tenant_id: Optional[int] = Field(None, description="Tenant ID")
    is_embassy: Optional[bool] = Field(False, description="Is embassy")
    embassy_dta: Optional[Decimal] = Field(Decimal('0.00'), description="Embassy DTA")
    rule_3121_section_ii: Optional[bool] = Field(
        False, description="Rule 3.1.21 Section II"
    )
    use_previous_tariff: Optional[bool] = Field(False, description="Use previous tariff")
    use_payment_date_fi: Optional[bool] = Field(False, description="Use payment date FI")
    add_state_supplier_record_505: Optional[bool] = Field(
        False, description="Add state supplier record 505"
    )
    customs_value_calculation: Optional[bool] = Field(
        False, description="Customs value calculation"
    )
    two_decimals_unit_value: Optional[bool] = Field(
        False, description="Two decimals unit value"
    )
    customs_value_per_item: Optional[bool] = Field(
        False, description="Customs value per item"
    )
    is_national_supplier: Optional[bool] = Field(
        False, description="Is national supplier"
    )
    is_consolidated: Optional[bool] = Field(False, description="Is consolidated")


class PedimentoConfigParametersCreate(PedimentoConfigParametersBase):
    """Schema for creating a new Pedimento Config Parameters"""

    pass


class PedimentoConfigParametersUpdate(BaseModel):
    """Schema for updating a Pedimento Config Parameters"""

    is_embassy: Optional[bool] = None
    embassy_dta: Optional[Decimal] = None
    rule_3121_section_ii: Optional[bool] = None
    use_previous_tariff: Optional[bool] = None
    use_payment_date_fi: Optional[bool] = None
    add_state_supplier_record_505: Optional[bool] = None
    customs_value_calculation: Optional[bool] = None
    two_decimals_unit_value: Optional[bool] = None
    customs_value_per_item: Optional[bool] = None
    is_national_supplier: Optional[bool] = None
    is_consolidated: Optional[bool] = None


class PedimentoConfigParametersResponse(PedimentoConfigParametersBase):
    """Schema for Pedimento Config Parameters response"""

    id: int
    created_at: datetime

    model_config = ConfigDict(from_attributes=True)
