#!/usr/bin/env python3
"""
Script to generate analysis summary for GitHub Actions
"""
import json
import os

def generate_summary():
    try:
        if not os.path.exists("llm_analysis_results.json"):
            print("### ❌ Analysis Failed")
            print("No results file was generated. Check the logs for errors.")
            return False
            
        with open("llm_analysis_results.json", "r") as f:
            results = json.load(f)
        
        summary = results.get("summary", {})
        print("✅ **Analysis Completed Successfully**")
        print("- Files retrieved: {}".format(summary.get("total_files_retrieved", 0)))
        print("- Batches processed: {}".format(summary.get("batches_processed", 0)))
        print("- Documents analyzed: {}".format(summary.get("total_documents_analyzed", 0)))
        print("- Success rate: {}/{} batches".format(summary.get("successful_llm_batches", 0), summary.get("batches_processed", 1)))
        
        return True
        
    except Exception as e:
        print("❌ Error generating summary: {}".format(e))
        return False

if __name__ == "__main__":
    success = generate_summary()
    exit(0 if success else 1)
