"""
Test script to verify notification system is working
Run: python manage.py shell < test_notifications.py
"""

print("=" * 60)
print("NOTIFICATION SYSTEM TEST")
print("=" * 60)

from custom_admin.models import AdminNotification
from custom_admin.utils.notification_utils import create_admin_notification

# Test 1: Check notification types
print("\n1. Checking notification types...")
types = [t[0] for t in AdminNotification.NOTIFICATION_TYPES]
print(f"   Total types: {len(types)}")
print(f"   Types: {', '.join(types[:5])}...")
assert len(types) == 15, "Should have 15 notification types"
print("   ✅ PASS")

# Test 2: Create test notification
print("\n2. Creating test notification...")
try:
    notification = create_admin_notification(
        notification_type='new_application',
        title='Test Notification',
        message='This is a test notification',
        link='/test/',
    )
    print(f"   Created notification ID: {notification.id}")
    print("   ✅ PASS")
except Exception as e:
    print(f"   ❌ FAIL: {str(e)}")

# Test 3: Check unread count
print("\n3. Checking unread count...")
unread = AdminNotification.get_unread_count()
print(f"   Unread notifications: {unread}")
print("   ✅ PASS")

# Test 4: Mark as read
print("\n4. Testing mark as read...")
try:
    notification.mark_as_read()
    assert notification.is_read == True
    print("   ✅ PASS")
except Exception as e:
    print(f"   ❌ FAIL: {str(e)}")

# Test 5: Check signals are registered
print("\n5. Checking if signals are registered...")
try:
    import custom_admin.signals
    print("   Signals module imported successfully")
    print("   ✅ PASS")
except Exception as e:
    print(f"   ❌ FAIL: {str(e)}")

# Test 6: Check recent notifications
print("\n6. Checking recent notifications...")
recent = AdminNotification.get_recent_unread(limit=5)
print(f"   Recent unread: {recent.count()}")
print("   ✅ PASS")

# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
total = AdminNotification.objects.count()
unread = AdminNotification.get_unread_count()
read = total - unread
print(f"Total notifications: {total}")
print(f"Unread: {unread}")
print(f"Read: {read}")
print("\n✅ All tests passed! Notification system is working.")
print("=" * 60)

# Cleanup test notification
if notification:
    notification.delete()
    print("\n🧹 Test notification cleaned up")
