from decimal import Decimal
from typing import List, Optional

from pydantic import BaseModel, Field


class ValueManifestationBaseDTO(BaseModel):
    manifestation_number: Optional[str] = Field(None, max_length=100, description="Manifestation number")
    pedimento: Optional[str] = Field(None, max_length=15, description="Pedimento")
    periodicity: Optional[str] = Field(None, max_length=10, description="Periodicity")
    semester: Optional[int] = Field(None, description="Semester")
    year: Optional[str] = Field(None, max_length=4, description="Year")
    pedimento_type: Optional[str] = Field(None, max_length=3, description="Pedimento type")
    aa_code: Optional[str] = Field(None, max_length=5, description="AA code")
    patent: Optional[str] = Field(None, max_length=4, description="Patent")
    first_name: Optional[str] = Field(None, max_length=80, description="First name")
    last_name_paternal: Optional[str] = Field(None, max_length=80, description="Last name paternal")
    last_name_maternal: Optional[str] = Field(None, max_length=80, description="Last name maternal")
    methods_count: Optional[int] = Field(None, description="Methods count")
    merchandise_value_method: Optional[str] = Field(None, max_length=10, description="Merchandise value method")
    transaction_value: Optional[int] = Field(None, description="Transaction value")
    identical_merchandise_value: Optional[int] = Field(None, description="Identical merchandise value")
    similar_merchandise_value: Optional[int] = Field(None, description="Similar merchandise value")
    unit_sale_price_value: Optional[int] = Field(None, description="Unit sale price value")
    reconstructed_value: Optional[int] = Field(None, description="Reconstructed value")
    article_78_value: Optional[int] = Field(None, description="Article 78 value")
    provisional_value_declaration: Optional[int] = Field(None, description="Provisional value declaration")
    has_attachments: Optional[int] = Field(None, description="Has attachments")
    attachment_pages_number: Optional[str] = Field(None, max_length=100, description="Attachment pages number")
    transaction_value_paid_price: Optional[Decimal] = Field(None, description="Transaction value paid price")
    price_pre_invoice: Optional[int] = Field(None, description="Price pre invoice")
    price_other_docs: Optional[int] = Field(None, description="Price other docs")
    concept_article_66: Optional[int] = Field(None, description="Concept article 66")
    concept_article_66_breakdown: Optional[int] = Field(None, description="Concept article 66 breakdown")
    attachment_article_66: Optional[str] = Field(None, max_length=2, description="Attachment article 66")
    prepaid_merchandise_article_65: Optional[str] = Field(None, max_length=2, description="Prepaid merchandise article 65")
    attachment_article_65: Optional[str] = Field(None, max_length=2, description="Attachment article 65")
    tax_base_no_sale: Optional[str] = Field(None, max_length=2, description="Tax base no sale")
    exists_circumstances_article_67_71: Optional[str] = Field(None, max_length=2, description="Exists circumstances article 67 71")
    customs_value_attachment: Optional[str] = Field(None, max_length=2, description="Customs value attachment")
    provisional_value_determination: Optional[str] = Field(None, max_length=2, description="Provisional value determination")
    merchandise_value_proof_attachment: Optional[str] = Field(None, max_length=2, description="Merchandise value proof attachment")
    legal_rep_rfc: Optional[str] = Field(None, max_length=30, description="Legal rep RFC")
    legal_representative: Optional[str] = Field(None, max_length=100, description="Legal representative")
    date: Optional[int] = Field(None, description="Date")
    selected_invoice: Optional[str] = Field(None, max_length=20, description="Selected invoice")
    invoice_option: Optional[str] = Field(None, max_length=3, description="Invoice option")
    importer_to_use: Optional[str] = Field(None, max_length=8, description="Importer to use")


class ValueManifestationCreateDTO(ValueManifestationBaseDTO):
    pass


class ValueManifestationUpdateDTO(ValueManifestationBaseDTO):
    pass


class ValueManifestationResponseDTO(ValueManifestationBaseDTO):
    id: int
    tenant_id: int
    company_id: int

    class Config:
        from_attributes = True


class ValueManifestationListDTO(BaseModel):
    items: List[ValueManifestationResponseDTO]
    total: int
    page: int
    page_size: int

    class Config:
        from_attributes = True
