import os
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()

from reports.export_service import ReportExportService
from decimal import Decimal
from datetime import date

s = ReportExportService()

data = {
    'loans': [{
        'loan_number': 'LOAN-001',
        'borrower_name': 'Test User',
        'principal_amount': Decimal('10000'),
        'disbursement_date': date(2024, 1, 1)
    }]
}

filters = {'start_date': date(2024, 1, 1), 'end_date': date(2024, 1, 31)}

# Test Excel export
print("Testing Excel Export...")
r = s.export_to_excel(data, 'test_report', filters)
print(f'✓ Status: {r.status_code}')
print(f'✓ Content-Type: {r["Content-Type"]}')
print(f'✓ Content-Disposition: {r["Content-Disposition"]}')
print(f'✓ Content Length: {len(r.content)} bytes')

# Test PDF export
print("\nTesting PDF Export...")
r2 = s.export_to_pdf(data, 'test_report', filters)
print(f'✓ Status: {r2.status_code}')
print(f'✓ Content-Type: {r2["Content-Type"]}')
print(f'✓ Content-Disposition: {r2["Content-Disposition"]}')
print(f'✓ Content Length: {len(r2.content)} bytes')
print(f'✓ PDF Header: {r2.content[:4]}')

print("\n✅ All exports work correctly!")
