import sys
import json
import os

def main() -> None:
 # Read prompt from stdin
 try:
  prompt = sys.stdin.read()
 except Exception:
  prompt = ""
 
 # 1. Epic Initialization
 if 'PATH: Epic Initialization' in prompt:
  mock_response = [
   {"id": "track-a", "goal": "Track A Goal", "title": "Track A"},
   {"id": "track-b", "goal": "Track B Goal", "title": "Track B"}
  ]
  print(json.dumps({
   "type": "message",
   "role": "assistant",
   "content": json.dumps(mock_response)
  }), flush=True)
  print(json.dumps({
   "type": "result",
   "status": "success",
   "stats": {"total_tokens": 100, "input_tokens": 50, "output_tokens": 50},
   "session_id": "mock-epic"
  }), flush=True)
  return

 # 2. Sprint Planning (different tickets for different tracks)
 if 'generate the implementation tickets' in prompt:
  track_label = "A" if "Track A" in prompt else "B"
  mock_response = [
   {"id": f"ticket-{track_label}-1", "description": f"Ticket {track_label} 1", "status": "todo", "assigned_to": "worker", "depends_on": []}
  ]
  print(json.dumps({
   "type": "message",
   "role": "assistant",
   "content": json.dumps(mock_response)
  }), flush=True)
  print(json.dumps({
   "type": "result",
   "status": "success",
   "stats": {"total_tokens": 100, "input_tokens": 50, "output_tokens": 50},
   "session_id": f"mock-sprint-{track_label}"
  }), flush=True)
  return

 # 3. Worker Execution
 if 'You are assigned to Ticket' in prompt:
  # Extract ticket ID
  import re
  match = re.search(r'Ticket (ticket-[A-Ba-b]-1)', prompt, re.IGNORECASE)
  tid = match.group(1) if match else "unknown"

  print(json.dumps({
   "type": "message",
   "role": "assistant",
   "content": f"Working on {tid}. Done."
  }), flush=True)
  print(json.dumps({
   "type": "result",
   "status": "success",
   "stats": {"total_tokens": 50, "input_tokens": 25, "output_tokens": 25},
   "session_id": f"mock-worker-{tid}"
  }), flush=True)
  return

 # Default
 print(json.dumps({
  "type": "message",
  "role": "assistant",
  "content": f"Mock response. Received prompt: {prompt[:100]}..."
 }), flush=True)
 print(json.dumps({
  "type": "result",
  "status": "success",
  "stats": {"total_tokens": 10, "input_tokens": 5, "output_tokens": 5},
  "session_id": "mock-default"
 }), flush=True)

if __name__ == "__main__":
 main()
