#!/usr/bin/env python3
"""
Update report HTML with fixed reference section.
Run this with the Flask shell: flask shell < update_references.py
"""

# Get all reports with references
reports = Report.query.filter(
    Report.synthesis_result.isnot(None),
    Report.report_references.isnot(None)
).all()

print(f"Found {len(reports)} reports to update")

from app.ai.report_generator import generate_report_html
from app.extensions import sanitize_html

for report in reports:
    # Regenerate HTML with new reference format
    new_html = generate_report_html(
        report.synthesis_result,
        report.language,
        report.report_references
    )
    report.full_report_html = sanitize_html(new_html)
    print(f"Updated report {report.id}: {report.project_name[:50]}...")

db.session.commit()
print("\nAll reports updated successfully!")
print("You can now refresh the report pages to see the fixed references section.")
