from pydantic import BaseModel
from typing import Optional


class NetworkNode(BaseModel):
    id: str           # IATA code
    name: Optional[str] = None
    lat: float
    lon: float
    total_flights: int = 0
    avg_delay: Optional[float] = None
    pct_delayed: Optional[float] = None
    delay_score: Optional[float] = None
    recovery_score: Optional[float] = None


class NetworkEdge(BaseModel):
    source: str
    target: str
    flight_count: int = 0
    avg_delay: Optional[float] = None
    pct_delayed: Optional[float] = None
    delay_risk: Optional[str] = None


class NetworkResponse(BaseModel):
    nodes: list[NetworkNode]
    edges: list[NetworkEdge]
    meta: dict


class StatsResponse(BaseModel):
    total_flights: int
    total_airports: int
    total_routes: int
    avg_delay_minutes: float
    pct_flights_delayed: float
    worst_airports: list[dict]
    worst_routes: list[dict]
    delay_causes: dict
