# ================================================================
# services/data/app/external/models/madrid_models.py
# ================================================================
"""
Data structures, enums, and dataclasses for Madrid traffic system
"""

from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import Optional


class TrafficServiceLevel(Enum):
    """Madrid traffic service levels"""
    FLUID = 0
    DENSE = 1
    CONGESTED = 2
    BLOCKED = 3


class CongestionLevel(Enum):
    """Standardized congestion levels"""
    LOW = "low"
    MEDIUM = "medium" 
    HIGH = "high"
    BLOCKED = "blocked"


@dataclass
class MeasurementPoint:
    """Madrid measurement point data structure"""
    id: str
    latitude: float
    longitude: float
    distance: float
    name: str
    type: str


@dataclass
class TrafficRecord:
    """Standardized traffic record with pedestrian inference"""
    date: datetime
    traffic_volume: int
    occupation_percentage: int
    load_percentage: int
    average_speed: int
    congestion_level: str
    pedestrian_count: int
    measurement_point_id: str
    measurement_point_name: str
    road_type: str
    source: str
    district: Optional[str] = None
    
    # Madrid-specific data
    intensidad_raw: Optional[int] = None
    ocupacion_raw: Optional[int] = None
    carga_raw: Optional[int] = None
    vmed_raw: Optional[int] = None
    
    # Pedestrian inference metadata
    pedestrian_multiplier: Optional[float] = None
    time_pattern_factor: Optional[float] = None
    district_factor: Optional[float] = None