import os

BASE_DIR = os.path.abspath(os.path.dirname(__file__))

class Config:
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'deployhub-secret-key-unity-2026-secure'
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or f"sqlite:///{os.path.join(BASE_DIR, 'database', 'deploy_manager.db')}"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    
    # Storage Paths
    STORAGE_DIR = os.path.join(BASE_DIR, 'storage')
    UPLOADS_DIR = os.path.join(STORAGE_DIR, 'uploads')
    BACKUPS_DIR = os.path.join(STORAGE_DIR, 'backups')
    KEYS_DIR = os.path.join(STORAGE_DIR, 'keys')
    LOGS_DIR = os.path.join(STORAGE_DIR, 'logs')
    
    # Default SSH key path
    DEFAULT_SSH_KEY_PATH = os.path.join(KEYS_DIR, 'id_rsa')

def ensure_directories():
    os.makedirs(os.path.join(BASE_DIR, 'database'), exist_ok=True)
    os.makedirs(Config.STORAGE_DIR, exist_ok=True)
    os.makedirs(Config.UPLOADS_DIR, exist_ok=True)
    os.makedirs(Config.BACKUPS_DIR, exist_ok=True)
    os.makedirs(Config.KEYS_DIR, exist_ok=True)
    os.makedirs(Config.LOGS_DIR, exist_ok=True)

ensure_directories()
