#!/usr/bin/env python
"""Verify imported Grazuri users"""
import os
import django
import base64

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()

from users.models import CustomUser

print("=" * 80)
print("Verifying Imported Grazuri Users")
print("=" * 80)

# Get all users
all_users = CustomUser.objects.all().order_by('username')
print(f"\nTotal users in system: {all_users.count()}\n")

# Show imported Grazuri users
grazuri_usernames = ['gladys', 'jmwangi', 'andmin', 'gts']
print("Imported Grazuri Users:")
print("-" * 80)

for username in grazuri_usernames:
    try:
        user = CustomUser.objects.get(username=username)
        print(f"\n✓ {user.first_name} {user.last_name} ({user.username})")
        print(f"  Email: {user.email}")
        print(f"  Phone: {user.phone_number}")
        print(f"  Role: {user.role}")
        print(f"  Branch: {user.branch.name if user.branch else 'None'}")
        print(f"  Status: {user.status}")
        print(f"  Staff: {user.is_staff}")
        print(f"  Active: {user.is_active}")
        
        # Show accessible branches for staff
        if user.is_staff:
            branches = user.accessible_branches.all()
            print(f"  Accessible Branches: {', '.join([b.name for b in branches])}")
            
    except CustomUser.DoesNotExist:
        print(f"\n❌ User '{username}' not found!")

print("\n" + "=" * 80)
print("All Users in System:")
print("=" * 80)
for user in all_users:
    print(f"  - {user.username} ({user.first_name} {user.last_name}) - {user.role}")

print("\n" + "=" * 80)
