import os
from dataclasses import dataclass


@dataclass
class Config:
    # Database
    DB_HOST: str = os.getenv("POSTGRES_HOST", "fr24-postgres")
    DB_PORT: int = int(os.getenv("POSTGRES_PORT", "5432"))
    DB_NAME: str = os.getenv("POSTGRES_DB", "fr24")
    DB_USER: str = os.getenv("POSTGRES_USER", "fr24")
    DB_PASSWORD: str = os.getenv("POSTGRES_PASSWORD", "change-me")

    # FlightAware AeroAPI
    FA_API_KEY: str = os.getenv("FLIGHTAWARE_API_KEY", "")
    FA_API_BASE: str = "https://aeroapi.flightaware.com/aeroapi"

    # Rate limit: conservative for Personal tier (500 req/month)
    RATE_LIMIT_SEC: float = float(os.getenv("FA_RATE_LIMIT_SEC", "2.0"))

    @property
    def DB_DSN(self) -> str:
        return (
            f"host={self.DB_HOST} port={self.DB_PORT} "
            f"dbname={self.DB_NAME} user={self.DB_USER} "
            f"password={self.DB_PASSWORD}"
        )


config = Config()
