from decimal import Decimal
from typing import List, Optional

from pydantic import BaseModel, Field


class ManifestBaseDTO(BaseModel):
    manifest_number: Optional[str] = Field(None, max_length=15, description="Manifest number")
    importer_details: Optional[str] = Field(None, max_length=60, description="Importer details")
    person_in_charge: Optional[str] = Field(None, max_length=60, description="Person in charge")
    consigned_to: Optional[str] = Field(None, max_length=8, description="Consigned to")
    sent_by: Optional[str] = Field(None, max_length=8, description="Sent by")
    foreign_exit_port: Optional[str] = Field(None, max_length=6, description="Foreign exit port")
    foreign_exit_port_loc: Optional[str] = Field(None, max_length=4, description="Foreign exit port location")
    destination_port: Optional[str] = Field(None, max_length=6, description="Destination port")
    destination_port_loc: Optional[str] = Field(None, max_length=4, description="Destination port location")
    entry_port: Optional[str] = Field(None, max_length=6, description="Entry port")
    entry_port_loc: Optional[str] = Field(None, max_length=4, description="Entry port location")
    entry_date: Optional[int] = Field(None, description="Entry date")
    net_weight: Optional[Decimal] = Field(None, description="Net weight")
    gross_weight: Optional[Decimal] = Field(None, description="Gross weight")
    total_value: Optional[Decimal] = Field(None, description="Total value")
    description: Optional[str] = Field(None, max_length=2500, description="Description")
    broker_code: Optional[str] = Field(None, max_length=5, description="Broker code")
    carrier_code: Optional[str] = Field(None, max_length=5, description="Carrier code")
    payment_invoice_number: Optional[str] = Field(None, max_length=5, description="Payment invoice number")
    seal_number: Optional[str] = Field(None, max_length=30, description="Seal number")
    entry_hour: Optional[int] = Field(None, description="Entry hour")
    hazardous_material: Optional[str] = Field(None, max_length=2, description="Hazardous material")
    transport_mode: Optional[str] = Field(None, max_length=2, description="Transport mode")
    transport_code: Optional[str] = Field(None, max_length=14, description="Transport code")
    trailer_number: Optional[str] = Field(None, max_length=20, description="Trailer number")
    status: Optional[str] = Field(None, max_length=14, description="Status")
    status_description: Optional[str] = Field(None, max_length=1000, description="Status description")
    manifest_type: Optional[str] = Field(None, max_length=3, description="Manifest type")


class ManifestCreateDTO(ManifestBaseDTO):
    pass


class ManifestUpdateDTO(ManifestBaseDTO):
    pass


class ManifestResponseDTO(ManifestBaseDTO):
    id: int
    tenant_id: int
    company_id: int

    class Config:
        from_attributes = True


class ManifestListDTO(BaseModel):
    items: List[ManifestResponseDTO]
    total: int
    page: int
    page_size: int

    class Config:
        from_attributes = True


class InvoiceManifestUpdateDTO(BaseModel):
    manifest_number: Optional[str] = Field(None, max_length=15, description="Manifest number")
