from functools import lru_cache
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    API_KEY: str
    API_KEY_NAME: str = "X-API-KEY"
    SECRET_KEY: str
    ENVIRONMENT: str
    DATA_BUCKET: str
    PLAN_TRIGGER_BUCKET: str
    ENGINE_SQS_URL: str

    # Third parties
    EPC_AUTH_TOKEN: str
    GOOGLE_SOLAR_API_KEY: str

    # Database settings
    DB_HOST: str
    DB_PASSWORD: str
    DB_USERNAME: str
    DB_PORT: str
    DB_NAME: str

    # Prediction buckets
    SAP_PREDICTIONS_BUCKET: str
    CARBON_PREDICTIONS_BUCKET: str
    HEAT_PREDICTIONS_BUCKET: str
    # LIGHTING_COST_PREDICTIONS_BUCKET: str
    # HEATING_COST_PREDICTIONS_BUCKET: str
    # HOT_WATER_COST_PREDICTIONS_BUCKET: str
    HEATING_KWH_PREDICTIONS_BUCKET: str
    HOTWATER_KWH_PREDICTIONS_BUCKET: str

    # Other S3 buckts
    ENERGY_ASSESSMENTS_BUCKET: str

    class Config:
        env_file = "backend/.env"


@lru_cache()
def get_settings():
    return Settings()


@lru_cache()
def get_prediction_buckets():
    return {
        "sap_change_predictions": get_settings().SAP_PREDICTIONS_BUCKET,
        "heat_demand_predictions": get_settings().HEAT_PREDICTIONS_BUCKET,
        "carbon_change_predictions": get_settings().CARBON_PREDICTIONS_BUCKET,
        "heating_kwh_predictions": get_settings().HEATING_KWH_PREDICTIONS_BUCKET,
        "hotwater_kwh_predictions": get_settings().HOTWATER_KWH_PREDICTIONS_BUCKET,
    }
