import os
from pathlib import Path
from backend.app.config import get_settings
from dotenv import load_dotenv

load_dotenv(Path(__file__).resolve().parent / "backend" / ".env")

DEFAULT_ENV = {
    "API_KEY": "test",
    "SECRET_KEY": "test",
    "ENVIRONMENT": "test",
    "DATA_BUCKET": "test",
    "PLAN_TRIGGER_BUCKET": "test",
    "ENGINE_SQS_URL": "test",
    "EPC_AUTH_TOKEN": os.getenv(
        "EPC_AUTH_TOKEN",
        "test",
    ),  # overridden in GitHub Actions
    "OPEN_EPC_API_TOKEN": os.getenv(
        "OPEN_EPC_API_TOKEN",
        "test",
    ),  # overridden in GitHub Actions
    "GOOGLE_SOLAR_API_KEY": "test",
    "DB_HOST": "localhost",
    "DB_USERNAME": "test",
    "DB_PASSWORD": "test",
    "DB_PORT": "5432",
    "DB_NAME": "test",
    "SAP_PREDICTIONS_BUCKET": "test",
    "CARBON_PREDICTIONS_BUCKET": "test",
    "HEAT_PREDICTIONS_BUCKET": "test",
    "HEATING_KWH_PREDICTIONS_BUCKET": "test",
    "HOTWATER_KWH_PREDICTIONS_BUCKET": "test",
    "ENERGY_ASSESSMENTS_BUCKET": "test",
    "HUBSPOT_API_KEY": "changeme",
}

# runs immediately when pytest starts, BEFORE collection
for k, v in DEFAULT_ENV.items():
    os.environ.setdefault(k, v)

# clear cached settings AFTER env is final
get_settings.cache_clear()
