#!/usr/bin/env python
"""
Verify that Django settings.py has been updated with Haven Grazuri contact information.
This script validates Task 8.1 completion.
"""

import os
import sys
import django

# Setup Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()

from django.conf import settings

def verify_settings():
    """Verify all required settings have been updated."""
    
    print("=" * 70)
    print("VERIFYING DJANGO SETTINGS UPDATE - TASK 8.1")
    print("=" * 70)
    print()
    
    # Track verification results
    all_passed = True
    
    # 1. Verify ALLOWED_HOSTS
    print("1. ALLOWED_HOSTS:")
    expected_hosts = ['grazuri.uzuriapps.xyz', 'havengrazuri.co.ke']
    allowed_hosts = settings.ALLOWED_HOSTS
    print(f"   Current: {allowed_hosts}")
    
    hosts_ok = any(host in str(allowed_hosts) for host in expected_hosts)
    if hosts_ok:
        print("   ✓ PASSED: Haven Grazuri domains included")
    else:
        print("   ✗ FAILED: Haven Grazuri domains not found")
        all_passed = False
    print()
    
    # 2. Verify EMAIL_HOST_USER
    print("2. EMAIL_HOST_USER:")
    email_user = getattr(settings, 'EMAIL_HOST_USER', None)
    print(f"   Current: {email_user}")
    
    if email_user and 'havenin2023@gmail.com' in email_user:
        print("   ✓ PASSED: Updated to Haven Grazuri email")
    else:
        print("   ✗ FAILED: Not updated to Haven Grazuri email")
        all_passed = False
    print()
    
    # 3. Verify DEFAULT_FROM_EMAIL
    print("3. DEFAULT_FROM_EMAIL:")
    default_from = getattr(settings, 'DEFAULT_FROM_EMAIL', None)
    print(f"   Current: {default_from}")
    
    if default_from and 'havenin2023@gmail.com' in default_from:
        print("   ✓ PASSED: Set to Haven Grazuri email")
    else:
        print("   ✗ FAILED: Not set to Haven Grazuri email")
        all_passed = False
    print()
    
    # 4. Verify ADMIN_EMAIL
    print("4. ADMIN_EMAIL:")
    admin_email = getattr(settings, 'ADMIN_EMAIL', None)
    print(f"   Current: {admin_email}")
    
    if admin_email and 'havenin2023@gmail.com' in admin_email:
        print("   ✓ PASSED: Set to Haven Grazuri admin email")
    else:
        print("   ✗ FAILED: Not set to Haven Grazuri admin email")
        all_passed = False
    print()
    
    # 5. Verify SMS_SENDER_ID
    print("5. SMS_SENDER_ID:")
    sms_sender = getattr(settings, 'SMS_SENDER_ID', None)
    print(f"   Current: {sms_sender}")
    
    if sms_sender == 'HavGrazuri':
        print("   ✓ PASSED: Set to 'HavGrazuri'")
    else:
        print("   ✗ FAILED: Not set to 'HavGrazuri'")
        all_passed = False
    print()
    
    # 6. Verify MPESA_SHORTCODE
    print("6. MPESA_SHORTCODE:")
    mpesa_shortcode = getattr(settings, 'MPESA_SHORTCODE', None)
    print(f"   Current: {mpesa_shortcode}")
    
    if mpesa_shortcode == '4159523':
        print("   ✓ PASSED: Set to Haven Grazuri shortcode '4159523'")
    else:
        print("   ✗ FAILED: Not set to Haven Grazuri shortcode")
        all_passed = False
    print()
    
    # 7. Verify PASSWORD_RESET_DOMAIN
    print("7. PASSWORD_RESET_DOMAIN:")
    reset_domain = getattr(settings, 'PASSWORD_RESET_DOMAIN', None)
    print(f"   Current: {reset_domain}")
    
    if reset_domain and 'grazuri.uzuriapps.xyz' in reset_domain:
        print("   ✓ PASSED: Updated to Haven Grazuri domain")
    else:
        print("   ✗ FAILED: Not updated to Haven Grazuri domain")
        all_passed = False
    print()
    
    # Additional contact information
    print("8. Additional Contact Information:")
    company_phone = getattr(settings, 'COMPANY_PHONE_PRIMARY', None)
    company_whatsapp = getattr(settings, 'COMPANY_WHATSAPP', None)
    company_email = getattr(settings, 'COMPANY_EMAIL', None)
    
    print(f"   COMPANY_PHONE_PRIMARY: {company_phone}")
    print(f"   COMPANY_WHATSAPP: {company_whatsapp}")
    print(f"   COMPANY_EMAIL: {company_email}")
    
    if company_phone == '+254112941830':
        print("   ✓ PASSED: Company phone set correctly")
    else:
        print("   ✗ WARNING: Company phone not set")
    print()
    
    # Final summary
    print("=" * 70)
    if all_passed:
        print("✓ ALL VERIFICATIONS PASSED - TASK 8.1 COMPLETE")
        print()
        print("Summary of Updates:")
        print("  • ALLOWED_HOSTS: Updated to include Haven Grazuri domains")
        print("  • EMAIL_HOST_USER: havenin2023@gmail.com")
        print("  • DEFAULT_FROM_EMAIL: havenin2023@gmail.com")
        print("  • ADMIN_EMAIL: havenin2023@gmail.com")
        print("  • SMS_SENDER_ID: HavGrazuri")
        print("  • MPESA_SHORTCODE: 4159523")
        print("  • PASSWORD_RESET_DOMAIN: grazuri.uzuriapps.xyz")
        return 0
    else:
        print("✗ SOME VERIFICATIONS FAILED - REVIEW REQUIRED")
        return 1
    print("=" * 70)

if __name__ == '__main__':
    try:
        exit_code = verify_settings()
        sys.exit(exit_code)
    except Exception as e:
        print(f"✗ ERROR: {str(e)}")
        import traceback
        traceback.print_exc()
        sys.exit(1)
