#!/usr/bin/env python
"""Find loan 086"""
import os
import django

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

from loans.models import Loan

# Try different ways to find the loan
print("Searching for loan 086...")

# Try exact match
loan = Loan.objects.filter(loan_number='LOAN-000086').first()
if loan:
    print(f"Found with exact match: {loan.loan_number}")
else:
    print("Not found with exact match")

# Try contains
loans = Loan.objects.filter(loan_number__icontains='086')
print(f"\nFound {loans.count()} loans containing '086':")
for loan in loans:
    print(f"  - {loan.loan_number} - {loan.borrower.first_name} {loan.borrower.last_name}")

# List all loans
all_loans = Loan.objects.all().order_by('-created_at')[:10]
print(f"\nLast 10 loans created:")
for loan in all_loans:
    print(f"  - {loan.loan_number} - {loan.borrower.first_name} {loan.borrower.last_name} - Principal: {loan.principal_amount} - Fee: {loan.processing_fee}")
