from typing import Optional
from pydantic import BaseModel, Field, ConfigDict
from .models import PortType


class PortBase(BaseModel):
    port_code: str = Field(..., max_length=6, description="Port Code")
    description: Optional[str] = Field(
        None, max_length=20, description="Description")
    location_code: str = Field(..., max_length=4, description="Location Code")
    location_description: Optional[str] = Field(
        None, max_length=20, description="Location Description")
    port_type: PortType = Field(
        server_default=PortType.ENTRY, description="Port Type (ENTRY, EXIT, BOTH)")


class PortCreate(PortBase):
    pass


class PortUpdate(BaseModel):
    port_code: Optional[str] = Field(None, max_length=6)
    description: Optional[str] = Field(None, max_length=20)
    location_code: Optional[str] = Field(None, max_length=4)
    location_description: Optional[str] = Field(None, max_length=20)
    port_type: Optional[PortType] = None


class PortResponse(PortBase):
    id: int

    model_config = ConfigDict(from_attributes=True)
