#!/usr/bin/env python3
"""
Verify that production has the updated code
"""

import os

VIEW_FILE = 'loans/views.py'

print("🔍 Checking production code...")

if not os.path.exists(VIEW_FILE):
    print(f"❌ {VIEW_FILE} not found!")
    print("Are you in the correct directory?")
    exit(1)

with open(VIEW_FILE, 'r', encoding='utf-8') as f:
    content = f.read()

# Check for the new permission check
if 'is_superuser or request.user.is_staff or request.user.has_permission' in content:
    print("✅ NEW CODE FOUND - Updated permission check is present")
    print("   Line contains: if not (request.user.is_superuser or request.user.is_staff ...)")
elif 'if not request.user.has_permission(\'loans\', \'create\'):' in content:
    print("❌ OLD CODE FOUND - Still using old permission check")
    print("   Line contains: if not request.user.has_permission('loans', 'create'):")
    print("\n🔧 SOLUTION:")
    print("   The updated loans/views.py file was NOT uploaded to production")
    print("   You need to upload it from your local machine")
else:
    print("⚠️  Unknown code - can't determine version")

print("\n📋 Code around new_application function:")
print("=" * 60)

# Find and show the function
lines = content.split('\n')
in_function = False
line_count = 0

for i, line in enumerate(lines):
    if 'def new_application(request):' in line:
        in_function = True
        line_count = 0
    
    if in_function:
        print(f"{i+1:4d}: {line}")
        line_count += 1
        
        if line_count > 10:  # Show first 10 lines
            break

print("=" * 60)
