import os

# Base de datos
DB_ENGINE = os.getenv("DB_ENGINE", "sqlite")

POSTGRES_USER = os.getenv("POSTGRES_USER", "mypasteuser")
POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD", "mypastepassword")
POSTGRES_DB = os.getenv("POSTGRES_DB", "mypastedb")
POSTGRES_HOST = os.getenv("POSTGRES_HOST", "db")
POSTGRES_PORT = os.getenv("POSTGRES_PORT", "5432")

DB_URI_POSTGRES = f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB}"

DB_PATH = os.getenv("DB_PATH", "/app/database/database.db")
DB_URI_SQLITE = f"sqlite:///{DB_PATH}"

if DB_ENGINE == "postgres":
    SQLALCHEMY_DATABASE_URI = DB_URI_POSTGRES
    SQLALCHEMY_ENGINE_OPTIONS = {
        "pool_pre_ping": True,
        "pool_recycle": 1800,  # Recycle connections every 30 minutes
        "pool_size": 10,  # Set the pool size
        "max_overflow": 20  # Allow a maximum of 20 connections to exceed the pool size
    }
else:
    SQLALCHEMY_DATABASE_URI = DB_URI_SQLITE
    SQLALCHEMY_ENGINE_OPTIONS = {}

# Clave secreta para JWT
SECRET_KEY = os.getenv("SECRET_KEY", "lñkkjkjkñkljñkjñkljlkjñklljñkjñlkj")  # Mejor usar una clave generada al desplegar
JWT_ALGORITHM = os.getenv("JWT_ALGORITHM", "HS256")
JWT_EXP_DELTA_SECONDS = int(os.getenv("JWT_EXP_DELTA_SECONDS", 3600))

# Ruta para subir archivos
UPLOAD_FOLDER = os.getenv("UPLOAD_FOLDER", "/app/uploads")

# Configuración de SMTP
SMTP_SERVER = os.getenv("SMTP_SERVER", "priet.us")
SMTP_PORT = int(os.getenv("SMTP_PORT", 465))  # Usa 465 para SSL
SMTP_USERNAME = os.getenv("SMTP_USERNAME", "")
SMTP_PASSWORD = os.getenv("SMTP_PASSWORD", "")
SMTP_USE_TLS = os.getenv("SMTP_USE_TLS", "false").lower() == "true"
SMTP_USE_SSL = os.getenv("SMTP_USE_SSL", "true").lower() == "true"

# config.py
ROLE_STORAGE_LIMITS = {
    'admin': -1,  # Ilimitado
    'advanced': 2 * 1024**3,  # 2GB en bytes
    'user': 1 * 1024**3,  # 1GB en bytes
}

# Debugging (opcional)
if __name__ == "__main__":
    print("Current configuration:")
    print(f"DB_ENGINE: {DB_ENGINE}")
    print(f"SQLALCHEMY_DATABASE_URI: {SQLALCHEMY_DATABASE_URI}")
    print(f"JWT_ALGORITHM: {JWT_ALGORITHM}")
    print(f"JWT_EXP_DELTA_SECONDS: {JWT_EXP_DELTA_SECONDS}")
    print(f"UPLOAD_FOLDER: {UPLOAD_FOLDER}")
    print(f"SMTP_SERVER: {SMTP_SERVER}")
    print(f"SMTP_PORT: {SMTP_PORT}")
    print(f"SMTP_USERNAME: {SMTP_USERNAME}")
    print(f"SMTP_USE_TLS: {SMTP_USE_TLS}")
    print(f"SMTP_USE_SSL: {SMTP_USE_SSL}")

