
import sys
import os
from pathlib import Path

# Add backend to path
sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'backend'))

try:
    from database.connection import db
    
    print("Connecting to database...")
    with db.get_connection() as conn:
        with conn.cursor() as cursor:
            print("Fetching trading config...")
            cursor.execute("SELECT `config_key`, `config_value` FROM trading_config")
            results = cursor.fetchall()
            print("\n=== Current Trading Config ===")
            for row in results:
                # Handle DictCursor (returns dict) or normal cursor (returns tuple)
                if isinstance(row, dict):
                    print(f"{row.get('config_key')}: {row.get('config_value')}")
                else:
                    print(f"{row[0]}: {row[1]}")
            print("==============================\n")

            print("Fetching global strategy config...")
            try:
                cursor.execute("SELECT `config_key`, `config_value` FROM global_strategy_config")
                results = cursor.fetchall()
                print("\n=== Global Strategy Config ===")
                for row in results:
                    if isinstance(row, dict):
                        print(f"{row.get('config_key')}: {row.get('config_value')}")
                    else:
                        print(f"{row[0]}: {row[1]}")
                print("==============================\n")
            except Exception as e:
                print(f"Global strategy config fetch failed (might be empty or table missing): {e}")
            
except Exception as e:
    print(f"Error: {e}")
