the output is allways in this formate 
# 1. Final Outcome
The order was **Returned**. The reason for the return is because the customer received an **"incorrect item"**.

# 2. Key Notes
* There was an initial Riskified fraud check that was approved.
* Customer reported receiving the wrong item, resulting in a reship request and eventual return.
* There are several "Update Shipment Request" events logged, indicating modifications to the original shipment plan.
* Several automatic locks (FRAUD\_LOCK, REMORSE\_LOCK, ORDER\_LOCK) were created and resolved by automated systems
("fraudprocessor", "Scheduler", "ordermodorchestrator"), potentially indicating the order was held at various stages for
verification or processing.

# 3. Key Evidence
* From the entry with timestamp "2025-05-08 11:57:07.894000":
* `"text": "btc ci receive incorrect 0678821944 l proc pa first item is on sale and proc replacement l educ cx tf and
email and advise to return the incorrect item after she receive the correc"`
* This shows the customer received an "incorrect item" and was advised to return it.

# 4. Order Timeline Overview
* **Order Creation Timestamp**: 05/05/2025
* **Final Status**: Returned
* **Key Users/Teams**:
* CHARMAINE VELASCO (Human Operator)
* MACY'S COM (System Automation)
* ordermodorchestrator (System Automation)
* fraudprocessor (System Automation)
* Scheduler (System Automation)
* Riskified
* **Summary**: The order was created, underwent a fraud check, was shipped, and then a customer reported receiving the
wrong item. A reship was processed, a post-shipment adjustment was requested, and eventually the customer was advised to
return the incorrect item which resulted in refund and return invoice.

# 5. Critical Events (Chronological Breakdown)

* **Fraud Checks**
* 05/05/2025: RISK FRAUD CHECK ENABLED RESERVATION:WAITING FOR RISK RESP. ACCEPT(509),DENY(510) (System Automation -
MACY'S COM)
* 05/05/2025: RC: approved RD: Reviewed and approved by Riskified (System Automation - MACY'S COM)

* **Payment Actions**
* 05/05/2025: Payment AddedA0505 (System Automation - MACY'S COM)
* 05/07/2025: Payment collectedA0506 (System Automation - MACY'S COM)
* 05/07/2025: Payment SettledA0507 (System Automation - MACY'S COM)
* 05/08/2025: Refund Payment InitiatedA0514 (System Automation - MACY'S COM)
* 05/08/2025: Payment SettledA0507 (System Automation - MACY'S COM)
* 05/08/2025: Payment refund successfulA0511 (System Automation - MACY'S COM)

* **Customer Issues Reported**
* 05/08/2025: btc ci receive incorrect 0678821944 l proc pa first item is on sale and proc replacement l educ cx tf and
email and advise to return the incorrect item after she receive the correc (CHARMAINE VELASCO)

* **Claims and Risk Reviews**
* 05/08/2025: RISK ABUSE CHECK ENABLED RESERVATION: WAITING FOR RISK RESP BLOCKED (513), EXCLUDE (515), DECLINED (520)
(CHARMAINE VELASCO)
* 05/08/2025: ClaimId: 749729205_1_6, UPCNumbers: [197957189862-1-1], RequestAction: Reship, ReshipTo: BT, IssueType:
Wrong_Item (CHARMAINE VELASCO)
* 05/08/2025: CLAIMS REVIEWED AND APPROVED BY RISKIFIED. RESHIP PROCESSED SUCCESSFUL ClaimId: 749729205_1_6 (CHARMAINE
VELASCO)
* 05/08/2025: Claim has passed preliminary Abuse Screening (CHARMAINE VELASCO)

* **Cancellation/Return Triggers**
* 05/08/2025: btc ci receive incorrect 0678821944 l proc pa first item is on sale and proc replacement l educ cx tf and
email and advise to return the incorrect item after she receive the correc (CHARMAINE VELASCO)
* 05/08/2025: Return CreatedA0701 (System Automation - MACY'S COM)
* 05/08/2025: Return ConfirmedA0702 (System Automation - MACY'S COM)
* 05/08/2025: Return Invoice SettledA0504 (System Automation - MACY'S COM)

* **Post-resolution Access**
* 05/08/2025: Several "ADD\_NOTE" events by CHARMAINE VELASCO involving claim details, reship instructions, and customer
communication.


but the user required in json formate Final Outcome,Key Notes,Key Evidence,Order Timeline Overview,Critical Events (Chronological Breakdown)
in summary all that up response are coming 

# routes/summary_route.py
from flask import Blueprint, request, jsonify
from llm.vertex_ai import generate_summary

summary_bp = Blueprint('summary_bp', __name__)

@summary_bp.route("/api/ccx-genrate_summary", methods=["POST"])
def generate_summary_route():
    if not request.is_json:
        return jsonify({"error": "Request content-type must be application/json"}), 400
    
    data = request.get_json(silent=True)
    if data is None:
        return jsonify({"error": "Invalid JSON body"}), 400
    
    # Validate that data is a list (JSON array)
    if not isinstance(data, list):
        return jsonify({"error": "JSON body must be an array of objects"}), 400

    try:
        # Call the llm generate_summary function
        summary = generate_summary(data)
        return summary, 200
    except Exception as e:
        return jsonify({"error": f"Processing error: {str(e)}"}), 500