from sqlalchemy import Column, Integer, String, DateTime, Text, Enum as SQLEnum, BigInteger
from sqlalchemy.sql import func
from enum import Enum
from app.db.session import Base


class OverflightStatus(str, Enum):
    ACTIVE = "ACTIVE"
    INACTIVE = "INACTIVE"
    CANCELLED = "CANCELLED"


class Overflight(Base):
    __tablename__ = "overflights"
    
    id = Column(BigInteger, primary_key=True, autoincrement=True)
    registration = Column(String(16), nullable=False, index=True)
    pob = Column(Integer, nullable=True)  # Persons on board
    type = Column(String(32), nullable=True)  # Aircraft type
    departure_airfield = Column(String(64), nullable=True, index=True)  # Airfield they departed from
    destination_airfield = Column(String(64), nullable=True, index=True)  # Where they're heading
    status = Column(SQLEnum(OverflightStatus), nullable=False, default=OverflightStatus.ACTIVE, index=True)
    call_dt = Column(DateTime, nullable=False, index=True)  # Time of initial call
    qsy_dt = Column(DateTime, nullable=True)  # Time of frequency change (QSY)
    notes = Column(Text, nullable=True)
    created_dt = Column(DateTime, nullable=False, server_default=func.current_timestamp(), index=True)
    created_by = Column(String(16), nullable=True, index=True)
    updated_at = Column(DateTime, nullable=False, server_default=func.current_timestamp(), onupdate=func.current_timestamp())
