"""
Check which credentials are set for each branch
"""
import os
import django

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

from users.models import Branch

print("=" * 80)
print("BRANCH CREDENTIALS CHECK")
print("=" * 80)

branches = Branch.objects.filter(mpesa_shortcode__isnull=False).exclude(mpesa_shortcode='')

for branch in branches:
    print(f"\n{branch.name}")
    print("-" * 80)
    print(f"Shortcode: {branch.mpesa_shortcode}")
    print(f"Consumer Key: {branch.mpesa_consumer_key}")
    print(f"Consumer Secret: {branch.mpesa_consumer_secret[:20]}...{branch.mpesa_consumer_secret[-10:]}")
    
    # Check if they're the same
    if branches.count() > 1:
        print("\nComparing with other branches...")
        for other in branches:
            if other.id != branch.id:
                if branch.mpesa_consumer_key == other.mpesa_consumer_key:
                    print(f"⚠ WARNING: Same consumer key as {other.name}!")
                if branch.mpesa_consumer_secret == other.mpesa_consumer_secret:
                    print(f"⚠ WARNING: Same consumer secret as {other.name}!")

print("\n" + "=" * 80)
print("RECOMMENDATIONS")
print("=" * 80)
print("\nEach shortcode MUST have its own unique credentials.")
print("If Main and Juja are using the same credentials, you need to:")
print("1. Get the correct credentials for shortcode 4086675 from Safaricom")
print("2. Update the Main branch with those credentials")
print("3. Then register the URLs")
