import mysql.connector
import sys
from python.db_config import DB_CONFIG

conn = mysql.connector.connect(**DB_CONFIG)
cursor = conn.cursor()

# Activer ou désactiver le pack
action = sys.argv[1] if len(sys.argv) > 1 else 'status'

if action == 'enable':
    cursor.execute('''
        UPDATE app_config 
        SET config_value = 'true' 
        WHERE config_key = 'challenge_pack_enabled'
    ''')
    conn.commit()
    print("✓ Pack défis ACTIVÉ dans la boutique")
elif action == 'disable':
    cursor.execute('''
        UPDATE app_config 
        SET config_value = 'false' 
        WHERE config_key = 'challenge_pack_enabled'
    ''')
    conn.commit()
    print("✓ Pack défis DÉSACTIVÉ dans la boutique")
else:
    cursor.execute("SELECT config_value FROM app_config WHERE config_key = 'challenge_pack_enabled'")
    result = cursor.fetchone()
    status = result[0] if result else 'non configuré'
    print(f"Status actuel du pack défis: {status}")
    print("\nUsage:")
    print("  python toggle_challenge_pack.py enable   - Activer le pack")
    print("  python toggle_challenge_pack.py disable  - Désactiver le pack")

cursor.close()
conn.close()
