from typing import Optional, Literal
from pydantic import BaseModel, EmailStr


# ── Users ─────────────────────────────────────────────────────────────────────
class AdminUser(BaseModel):
    id: str
    name: Optional[str] = None
    email: Optional[str] = None
    phone: Optional[str] = None
    role: str = "citizen"


class AdminUserCreate(BaseModel):
    name: str
    password: str
    email: Optional[EmailStr] = None
    phone: Optional[str] = None
    role: Literal["citizen", "driver", "admin"] = "citizen"


class AdminUserUpdate(BaseModel):
    name: Optional[str] = None
    email: Optional[EmailStr] = None
    role: Optional[Literal["citizen", "driver", "admin"]] = None


# ── Routes ────────────────────────────────────────────────────────────────────
class AdminRoute(BaseModel):
    id: str
    name: Optional[str] = None
    truck_id: Optional[int] = None
    turno: Optional[str] = None
    status: str = "pendiente"
    current_position_id: int = 1


class AdminRouteCreate(BaseModel):
    id: str
    name: Optional[str] = None
    truck_id: Optional[int] = None
    turno: Optional[Literal["matutino", "vespertino", "Matutino", "Vespertino"]] = None
    status: Optional[
        Literal["pendiente", "en_ruta", "completada", "diferida", "reasignada"]
    ] = "pendiente"


class AdminRouteUpdate(BaseModel):
    name: Optional[str] = None
    truck_id: Optional[int] = None
    turno: Optional[Literal["matutino", "vespertino", "Matutino", "Vespertino"]] = None
    status: Optional[
        Literal["pendiente", "en_ruta", "completada", "diferida", "reasignada"]
    ] = None


# ── Units (camiones) ──────────────────────────────────────────────────────────
class AdminUnit(BaseModel):
    id: int
    plate: Optional[str] = None
    status: str = "active"


class AdminUnitCreate(BaseModel):
    id: int
    plate: Optional[str] = None
    status: Literal["active", "inactive", "maintenance"] = "active"


class AdminUnitUpdate(BaseModel):
    plate: Optional[str] = None
    status: Optional[Literal["active", "inactive", "maintenance"]] = None


# ── Drivers ───────────────────────────────────────────────────────────────────
class AdminDriver(BaseModel):
    id: str
    user_id: str
    user_name: Optional[str] = None
    user_email: Optional[str] = None
    unit_id: Optional[int] = None
    plate: Optional[str] = None


class AdminDriverCreate(BaseModel):
    user_id: str
    unit_id: Optional[int] = None


class AdminDriverUpdate(BaseModel):
    unit_id: Optional[int] = None
