# services/external/app/models/city_traffic.py
"""
City Traffic Data Model - Shared city-based traffic storage
"""

from sqlalchemy import Column, String, Integer, Float, DateTime, Text, Index
from sqlalchemy.dialects.postgresql import UUID, JSONB
from datetime import datetime
import uuid

from app.core.database import Base


class CityTrafficData(Base):
    """City-based historical traffic data"""

    __tablename__ = "city_traffic_data"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    city_id = Column(String(50), nullable=False, index=True)
    date = Column(DateTime(timezone=True), nullable=False, index=True)

    traffic_volume = Column(Integer, nullable=True)
    pedestrian_count = Column(Integer, nullable=True)
    congestion_level = Column(String(20), nullable=True)
    average_speed = Column(Float, nullable=True)

    source = Column(String(50), nullable=False)
    raw_data = Column(JSONB, nullable=True)

    created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
    updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow)

    __table_args__ = (
        Index('idx_city_traffic_lookup', 'city_id', 'date'),
    )
