from __future__ import annotations

import os
from typing import Optional

from dotenv import load_dotenv

load_dotenv()


class Settings:
    db_host: str
    db_port: int
    db_user: str
    db_password: str
    db_name: str
    allowed_origins: list[str]
    geoip_db_path: str
    playwright_executable: Optional[str]
    host: str
    port: int

    def __init__(self) -> None:
        self.db_host = os.getenv("DB_HOST", "localhost")
        self.db_port = int(os.getenv("DB_PORT", "5432"))
        self.db_user = os.getenv("DB_USER", "user")
        self.db_password = os.getenv("DB_PASSWORD", "password")
        self.db_name = os.getenv("DB_NAME", "sentinel_lens")

        origins_raw = os.getenv("ALLOWED_ORIGINS", "http://localhost:5173")
        self.allowed_origins = [o.strip() for o in origins_raw.split(",") if o.strip()]
        self.geoip_db_path = os.getenv("GEOIP_DB_PATH", "./GeoLite2-City.mmdb")
        self.playwright_executable = os.getenv("PLAYWRIGHT_EXECUTABLE") or None

        self.host = os.getenv("HOST", "0.0.0.0")
        self.port = int(os.getenv("PORT", "8000"))


settings = Settings()
