import sqlite3

def check_db():
    conn = sqlite3.connect("data/game_design_matrix.db")
    cur = conn.cursor()
    
    # 1. Integrity check
    cur.execute("PRAGMA integrity_check")
    integrity = cur.fetchall()
    print("Integrity check:", integrity)

    # 2. Foreign key check
    cur.execute("PRAGMA foreign_key_check")
    fk = cur.fetchall()
    print("FK check:", fk)

    # 3. Table info
    cur.execute("PRAGMA table_info(progression_benchmarks)")
    cols = cur.fetchall()
    print("Columns (total %d):" % len(cols))
    for c in cols:
        print(f"  cid={c[0]}, name={c[1]}, type={c[2]}, notnull={c[3]}, dflt_value={c[4]}, pk={c[5]}")

    # 4. Indexes
    cur.execute("PRAGMA index_list(progression_benchmarks)")
    indexes = cur.fetchall()
    print("Indexes on progression_benchmarks:", indexes)

    # 5. Spot check key rows
    cur.execute("""
        SELECT level, target_exp, exp_to_next_level, cumulative_exp, player_base_hp, 
               player_benchmark_dps, monster_base_hp, monster_base_dps, max_affix_tier_allowed, 
               death_penalty_ratio, level_gap_safe_range, level_gap_penalty_exp, monster_benchmark_exp
        FROM progression_benchmarks
        WHERE level IN (1, 20, 60, 61, 80, 81, 85, 90, 98, 99, 100)
        ORDER BY level ASC
    """)
    rows = cur.fetchall()
    print("\nSample rows:")
    for r in rows:
        print(f"  Lvl {r[0]:3d}: target_xp={r[1]:14,d}, exp_to_next={r[2]:12,d}, cum_xp={r[3]:14,d}, p_hp={r[4]:6.1f}, max_tier={r[8]:2d}, death_pen={r[9]:.2f}")

    conn.close()

if __name__ == "__main__":
    check_db()
