from typing import Optional

from pydantic import BaseModel, Field


TRANSPORTER_KEY_MAX_LENGTH = 30


class DriverBaseDTO(BaseModel):
    transporter_key: str = Field(..., max_length=TRANSPORTER_KEY_MAX_LENGTH)
    driver_id: Optional[int] = None
    line: int
    driver_name: Optional[str] = None
    license_number: Optional[str] = None
    express_line_id: Optional[str] = None
    ace_id: Optional[str] = None
    birth_date: Optional[int] = None
    gender: Optional[str] = None
    birth_country: Optional[str] = None
    hazardous_material_auth: Optional[str] = None
    hazardous_material_state: Optional[str] = None
    first_name: Optional[str] = None
    last_name: Optional[str] = None
    id_key1: Optional[str] = None
    id_number1: Optional[str] = None
    id_state1: Optional[str] = None
    id_country1: Optional[str] = None
    id_key2: Optional[str] = None
    id_number2: Optional[str] = None
    id_state2: Optional[str] = None
    id_country2: Optional[str] = None
    badge_number: Optional[str] = None
    class_type: Optional[str] = None
    unique_badge_number: Optional[str] = None
    company_id: int
    tenant_id: int


class DriverCreateDTO(DriverBaseDTO):
    pass


class DriverUpdateDTO(BaseModel):
    """All fields optional; transporter_key, line, company_id, tenant_id are not updated."""

    driver_name: Optional[str] = None
    license_number: Optional[str] = None
    express_line_id: Optional[str] = None
    ace_id: Optional[str] = None
    birth_date: Optional[int] = None
    gender: Optional[str] = None
    birth_country: Optional[str] = None
    hazardous_material_auth: Optional[str] = None
    hazardous_material_state: Optional[str] = None
    first_name: Optional[str] = None
    last_name: Optional[str] = None
    id_key1: Optional[str] = None
    id_number1: Optional[str] = None
    id_state1: Optional[str] = None
    id_country1: Optional[str] = None
    id_key2: Optional[str] = None
    id_number2: Optional[str] = None
    id_state2: Optional[str] = None
    id_country2: Optional[str] = None
    badge_number: Optional[str] = None
    class_type: Optional[str] = None
    unique_badge_number: Optional[str] = None


class DriverResponseDTO(DriverBaseDTO):
    class Config:
        from_attributes = True
