#!/usr/bin/env python3
"""
Verify that production settings are being loaded correctly.
"""

import os
import sys

def verify_production_settings():
    """Verify production settings are loaded."""
    print("🔍 Verifying Production Settings")
    print("=" * 40)
    
    # Set OpenBLAS environment variables first
    os.environ['OPENBLAS_NUM_THREADS'] = '1'
    os.environ['MKL_NUM_THREADS'] = '1'
    os.environ['OMP_NUM_THREADS'] = '1'
    
    try:
        # Set Django settings module to production
        os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ruralpoint_system.settings_production')
        
        # Import Django and setup
        import django
        django.setup()
        
        # Get settings
        from django.conf import settings
        
        print(f"✓ Django settings module: {settings.SETTINGS_MODULE}")
        print(f"✓ Debug mode: {settings.DEBUG}")
        print(f"✓ Allowed hosts: {settings.ALLOWED_HOSTS}")
        print(f"✓ CSRF trusted origins: {settings.CSRF_TRUSTED_ORIGINS}")
        
        # Check if the problematic host is allowed
        problematic_host = 'ruralpoint.branchbusinessadvance.co.ke'
        if problematic_host in settings.ALLOWED_HOSTS:
            print(f"✅ Host '{problematic_host}' is in ALLOWED_HOSTS")
        else:
            print(f"❌ Host '{problematic_host}' is NOT in ALLOWED_HOSTS")
        
        # Check CSRF settings
        if f"https://{problematic_host}" in settings.CSRF_TRUSTED_ORIGINS:
            print(f"✅ Host 'https://{problematic_host}' is in CSRF_TRUSTED_ORIGINS")
        else:
            print(f"❌ Host 'https://{problematic_host}' is NOT in CSRF_TRUSTED_ORIGINS")
        
        print("\n🎉 Production settings verification completed!")
        
    except Exception as e:
        print(f"❌ Verification failed: {e}")
        return False
    
    return True

if __name__ == "__main__":
    verify_production_settings()
