"""Replay the article's recorded two-role exchange; no API calls or purchases."""
import json
from pathlib import Path

ROOT = Path(__file__).resolve().parent
responses = json.loads((ROOT / 'responses.json').read_text())

def decode(role):
    text = responses[role]['content'].strip()
    if text.startswith('```json\n') and text.endswith('\n```'):
        text = text[len('```json\n'):-len('\n```')]
    return json.loads(text)

planner, reviewer = decode('planner'), decode('reviewer')
prices = {'Museum': 12, 'Garden': 0, 'Ferry': 15}
stops = planner['selected_stops']
valid_stops = len(stops) == 2 and len(set(stops)) == 2 and all(s in prices for s in stops)
computed = sum(prices[s] for s in stops) + 4 if valid_stops else None
checks = {
    'same_request_id': planner['request_id'] == reviewer['request_id'] == 'DEMO-10',
    'two_distinct_known_stops': valid_stops,
    'planner_arithmetic_correct': valid_stops and planner['admission_total_usd'] == computed - 4 and planner['travel_usd'] == 4 and planner['total_usd'] == computed,
    'within_budget': computed is not None and computed <= 20,
    'reviewer_arithmetic_correct': reviewer['independently_computed_total_usd'] == computed and reviewer['budget_remaining_usd'] == 20 - computed,
    'reviewer_accepts': reviewer['verdict'] == 'accept',
    'review_only': planner['proposed_action'] == 'review_only' and reviewer['action_taken'] == 'none',
}
report = {'request_id': 'DEMO-10', 'computed_total_usd': computed,
          'budget_remaining_usd': 20 - computed, 'checks': checks,
          'workflow_state': 'ready_for_human_review' if all(checks.values()) else 'needs_review',
          'action_taken': 'none'}
print(json.dumps(report, indent=2))
