#!/usr/bin/env python3
"""
Simple Script to Update Boost Plus Processing Fee in Production
=============================================================

This script only updates the Boost Plus processing fee setting to 2.0%
Run this in cPanel Terminal or Django shell.

Usage in cPanel Terminal:
    python update_boost_plus_settings.py

Usage in Django shell:
    exec(open('update_boost_plus_settings.py').read())
"""

import os
import django

# Set up Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()

from utils.models import SystemSetting

def update_boost_plus_processing_fee():
    """Update Boost Plus processing fee to 2.0%"""
    print("🔄 Updating Boost Plus Processing Fee...")
    
    try:
        # Update the setting
        setting, created = SystemSetting.objects.update_or_create(
            key='boost_plus_processing_fee',
            defaults={
                'value': '2.0',
                'category': 'loan',
                'description': 'Processing fee for Boost Plus loans (%) - one-time only',
                'is_public': True
            }
        )
        
        status = "Created" if created else "Updated"
        print(f"✅ {status} boost_plus_processing_fee: 2.0%")
        
        # Verify the change
        current_value = SystemSetting.get_float('boost_plus_processing_fee', 0)
        print(f"✅ Verified: boost_plus_processing_fee is now {current_value}%")
        
        return True
        
    except Exception as e:
        print(f"❌ Error updating setting: {str(e)}")
        return False

def verify_all_settings():
    """Verify all loan product settings"""
    print("\n🔍 Verifying All Loan Settings...")
    
    settings_to_check = [
        'boost_interest_rate',
        'boost_processing_fee',
        'boost_plus_interest_rate',
        'boost_plus_processing_fee',
        'mwamba_interest_rate',
        'mwamba_processing_fee',
        'imara_interest_rate',
        'imara_processing_fee'
    ]
    
    for key in settings_to_check:
        try:
            value = SystemSetting.get_float(key, 0)
            print(f"  {key}: {value}%")
        except Exception as e:
            print(f"  {key}: ERROR - {str(e)}")

if __name__ == "__main__":
    print("🚀 Boost Plus Settings Update Script")
    print("=" * 50)
    
    # Update the setting
    success = update_boost_plus_processing_fee()
    
    if success:
        # Verify all settings
        verify_all_settings()
        print("\n✅ Update completed successfully!")
        print("\nNext steps:")
        print("1. Check a Boost Plus loan detail page")
        print("2. Verify it shows 20% interest rate and 2% processing fee")
        print("3. Test creating a new loan application")
    else:
        print("\n❌ Update failed!")
        print("Please check the error message above and try again.")
