#!/usr/bin/env python3
"""
Script to check what users exist in the database
"""

import requests
import json

def check_users():
    """Check what users exist in the database"""
    
    # API endpoint to get all users
    url = "https://kisiwaapi.mutabletech.co.ke/api/v1/users"
    
    try:
        # Make the API call to get users
        response = requests.get(url)
        
        print(f"Status Code: {response.status_code}")
        
        if response.status_code == 200:
            data = response.json()
            if data.get('success'):
                users = data.get('data', {}).get('users', [])
                print(f"✅ Found {len(users)} users in the database:")
                print("-" * 80)
                
                for i, user in enumerate(users, 1):
                    print(f"{i}. ID: {user.get('id', 'N/A')}")
                    print(f"   Email: {user.get('email', 'N/A')}")
                    print(f"   Name: {user.get('first_name', 'N/A')} {user.get('last_name', 'N/A')}")
                    print(f"   Type: {user.get('user_type', 'N/A')}")
                    print(f"   Active: {user.get('is_active', 'N/A')}")
                    print("-" * 40)
                
                # Look for users with similar email addresses
                print("\n🔍 Searching for users with similar email addresses...")
                similar_emails = []
                for user in users:
                    email = user.get('email', '')
                    if 'kosgei' in email.lower() or 'rene' in email.lower():
                        similar_emails.append(user)
                
                if similar_emails:
                    print(f"\n✅ Found {len(similar_emails)} users with similar email addresses:")
                    for user in similar_emails:
                        print(f"   Email: {user.get('email')}")
                        print(f"   Name: {user.get('first_name')} {user.get('last_name')}")
                else:
                    print("\n❌ No users found with similar email addresses")
                    
            else:
                print("❌ Failed to get users")
                print(f"Response: {response.text}")
        else:
            print("❌ Failed to get users")
            print(f"Response: {response.text}")
            
    except requests.exceptions.ConnectionError:
        print("❌ Connection error: Make sure the server is accessible")
    except Exception as e:
        print(f"❌ Error: {e}")

if __name__ == "__main__":
    print("Checking users in the database...")
    print("=" * 50)
    
    check_users() 