﻿#!/usr/bin/env python
"""Show all users in Grazuri user table"""
import pymysql

conn = pymysql.connect(
    host='localhost',
    user='root',
    password='password',
    database='xygbfpsg_graz',
    charset='utf8mb4'
)

try:
    with conn.cursor() as cursor:
        # Check if user table exists
        cursor.execute("SHOW TABLES LIKE 'user'")
        if not cursor.fetchone():
            print("❌ Grazuri 'user' table does NOT exist")
        else:
            # Count records
            cursor.execute("SELECT COUNT(*) FROM user")
            count = cursor.fetchone()[0]
            print(f"\n{'=' * 100}")
            print(f"GRAZURI USER TABLE - Total Users: {count}")
            print('=' * 100)
            
            if count == 0:
                print("\n⚠️  The user table is EMPTY - no users to import!")
                print("\nPlease provide an SQL file that contains INSERT statements with actual user data.")
            else:
                # Show all users
                cursor.execute("""
                    SELECT userid, name, username, email, phone, role, 
                           gender, id_number, date_of_birth, branch 
                    FROM user 
                    ORDER BY userid
                """)
                users = cursor.fetchall()
                
                print(f"\nAll {count} users in Grazuri database:\n")
                for user in users:
                    print(f"ID: {user[0]}")
                    print(f"  Name: {user[1]}")
                    print(f"  Username: {user[2]}")
                    print(f"  Email: {user[3]}")
                    print(f"  Phone: {user[4]}")
                    print(f"  Role: {user[5]}")
                    print(f"  Gender: {user[6]}")
                    print(f"  ID Number: {user[7]}")
                    print(f"  DOB: {user[8]}")
                    print(f"  Branch: {user[9]}")
                    print()
                    
except Exception as e:
    print(f"❌ Error: {str(e)}")
finally:
    conn.close()
