import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

"""
config.py — Configuration du pipeline ETL Monera
Charge les variables d'environnement depuis server/.env (ou l'environnement OS).
"""

import os
import logging
from dotenv import load_dotenv
from pathlib import Path

# Remonte d'un niveau (server/etl/ → server/) pour charger server/.env
env_path = Path(__file__).resolve().parent.parent / ".env"
load_dotenv(dotenv_path=env_path, encoding="utf-8")

# ---------------------------------------------------------------------------
# MongoDB (OLTP)
# ---------------------------------------------------------------------------
MONGODB_URI: str = os.environ["MONGODB_URI"]          # obligatoire
MONGO_DB_NAME: str = os.getenv("MONGO_DB_NAME", "monera")

# ---------------------------------------------------------------------------
# PostgreSQL (OLAP / DWH)
# ---------------------------------------------------------------------------
POSTGRES_DSN: str = os.environ.get("POSTGRES_DSN_PYTHON") or os.environ["POSTGRES_DSN"]

# ---------------------------------------------------------------------------
# Comportement de l'ETL
# ---------------------------------------------------------------------------
BATCH_SIZE: int = int(os.getenv("ETL_BATCH_SIZE", "500"))

# ---------------------------------------------------------------------------
# Logging structuré
# ---------------------------------------------------------------------------
LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO").upper()

logging.basicConfig(
    level=getattr(logging, LOG_LEVEL, logging.INFO),
    format="%(asctime)s [%(levelname)s] %(name)s — %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S",
)

logger = logging.getLogger("monera_etl")
