"""Generate delivery phases 10.2-10.8 implementation files."""
from __future__ import annotations

from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def w(rel: str, content: str) -> None:
    path = ROOT / rel
    path.parent.mkdir(parents=True, exist_ok=True)
    path.write_text(content.rstrip() + "\n", encoding="utf-8")
    print(f"wrote {rel}")


# ---------------------------------------------------------------------------
# schemas/fleet.py
# ---------------------------------------------------------------------------
w(
    "app/schemas/fleet.py",
    '''"""Fleet & vehicle DTOs — Phase 10.2."""
from __future__ import annotations

from datetime import datetime
from decimal import Decimal
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field

from app.models.types import FleetStatus, VehicleAssignmentStatus, VehicleStatus
from app.schemas.common import ORMBase

_FORBID = ConfigDict(extra="forbid")


class FleetCreate(BaseModel):
    model_config = _FORBID

    organization_id: UUID
    hub_id: UUID | None = None
    code: str = Field(max_length=50)
    name: str = Field(max_length=255)
    description: str | None = None
    status: FleetStatus = FleetStatus.DRAFT
    metadata_json: dict | None = None


class FleetUpdate(BaseModel):
    model_config = _FORBID

    hub_id: UUID | None = None
    name: str | None = Field(default=None, max_length=255)
    description: str | None = None
    status: FleetStatus | None = None
    metadata_json: dict | None = None
    version: int = Field(ge=1)


class FleetRead(ORMBase):
    id: UUID
    tenant_id: UUID
    organization_id: UUID
    hub_id: UUID | None
    code: str
    name: str
    description: str | None
    status: FleetStatus
    metadata_json: dict | None
    version: int
    is_deleted: bool
    created_by: str | None
    updated_by: str | None
    created_at: datetime
    updated_at: datetime


class FleetListResponse(BaseModel):
    items: list[FleetRead]
    total: int
    page: int
    page_size: int


class VehicleTypeCreate(BaseModel):
    model_config = _FORBID

    code: str = Field(max_length=50)
    name: str = Field(max_length=255)
    description: str | None = None
    capacity_kg: float | None = None
    capacity_volume: float | None = None
    capability_tags: list[str] | None = None
    metadata_json: dict | None = None


class VehicleTypeUpdate(BaseModel):
    model_config = _FORBID

    name: str | None = Field(default=None, max_length=255)
    description: str | None = None
    capacity_kg: float | None = None
    capacity_volume: float | None = None
    capability_tags: list[str] | None = None
    metadata_json: dict | None = None
    version: int = Field(ge=1)


class VehicleTypeRead(ORMBase):
    id: UUID
    tenant_id: UUID
    code: str
    name: str
    description: str | None
    capacity_kg: float | None
    capacity_volume: float | None
    capability_tags: list | None
    metadata_json: dict | None
    version: int
    is_deleted: bool
    created_by: str | None
    updated_by: str | None
    created_at: datetime
    updated_at: datetime


class VehicleTypeListResponse(BaseModel):
    items: list[VehicleTypeRead]
    total: int
    page: int
    page_size: int


class VehicleCreate(BaseModel):
    model_config = _FORBID

    fleet_id: UUID
    vehicle_type_id: UUID
    code: str = Field(max_length=50)
    plate_number: str | None = Field(default=None, max_length=32)
    status: VehicleStatus = VehicleStatus.AVAILABLE
    metadata_json: dict | None = None


class VehicleUpdate(BaseModel):
    model_config = _FORBID

    plate_number: str | None = Field(default=None, max_length=32)
    status: VehicleStatus | None = None
    metadata_json: dict | None = None
    version: int = Field(ge=1)


class VehicleRead(ORMBase):
    id: UUID
    tenant_id: UUID
    fleet_id: UUID
    vehicle_type_id: UUID
    code: str
    plate_number: str | None
    status: VehicleStatus
    metadata_json: dict | None
    version: int
    is_deleted: bool
    created_by: str | None
    updated_by: str | None
    created_at: datetime
    updated_at: datetime


class VehicleListResponse(BaseModel):
    items: list[VehicleRead]
    total: int
    page: int
    page_size: int


class VehicleAssignmentCreate(BaseModel):
    model_config = _FORBID

    driver_id: UUID
    notes: str | None = None
    metadata_json: dict | None = None


class VehicleAssignmentUpdate(BaseModel):
    model_config = _FORBID

    status: VehicleAssignmentStatus | None = None
    notes: str | None = None
    metadata_json: dict | None = None


class VehicleAssignmentRead(ORMBase):
    id: UUID
    tenant_id: UUID
    vehicle_id: UUID
    driver_id: UUID
    status: VehicleAssignmentStatus
    notes: str | None
    metadata_json: dict | None
    is_deleted: bool
    created_by: str | None
    updated_by: str | None
    created_at: datetime
    updated_at: datetime
''',
)

print("Phase 10.2 schemas done — run full generator for remaining files")
