import os
import logging
from dotenv import load_dotenv

# Load variables from .env file if it exists
load_dotenv()

class Config:
    # --- Paths ---
    BASE_DIR = os.path.dirname(os.path.abspath(__file__))
    UPLOAD_FOLDER = os.getenv('UPLOAD_FOLDER', os.path.join(BASE_DIR, 'static'))
    ROI_FOLDER = os.path.join(UPLOAD_FOLDER, 'rois')
    
    # Configuration Files
    ROI_CONFIG_PATH = os.path.join(BASE_DIR, os.getenv('ROI_CONFIG_FILE', 'roi_config.json'))
    CAMERA_CONFIG_PATH = os.path.join(BASE_DIR, os.getenv('CAMERA_CONFIG_FILE', 'camera_config.json'))
    
    # Model Path
    MODEL_PATH = os.path.join(BASE_DIR, 'models', os.getenv('MODEL_FILE', 'dig-class11_1910_s2_q.tflite'))

    # --- MQTT Settings ---
    MQTT_BROKER = os.getenv('MQTT_BROKER', '127.0.0.1')
    MQTT_PORT = int(os.getenv('MQTT_PORT', 1883))
    MQTT_TOPIC = os.getenv('MQTT_TOPIC', 'homeassistant/sensor/RTSPCamDigitDetection/state')
    MQTT_USERNAME = os.getenv('MQTT_USERNAME', None)
    MQTT_PASSWORD = os.getenv('MQTT_PASSWORD', None)

    # --- App Settings ---
    DEBUG = os.getenv('DEBUG', 'False').lower() in ('true', '1', 't')
    LOG_LEVEL = getattr(logging, os.getenv('LOG_LEVEL', 'INFO').upper(), logging.INFO)
