#!/bin/bash

# Script to capture and compare Claude Code vs otto traffic
#
# SETUP:
# 1. Trust mitmproxy CA cert (run once):
#    sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/.mitmproxy/mitmproxy-ca-cert.pem
#
# 2. Start mitmproxy in one terminal:
#    mitmproxy -s scripts/capture-anthropic.py -p 8080
#
# USAGE:
#   ./scripts/capture-traffic.sh claude    # Capture real Claude Code requests
#   ./scripts/capture-traffic.sh otto       # Capture otto spoofed requests

set -e

PROXY="http://127.0.0.1:8080"

if [ "$1" == "claude" ]; then
    echo "Starting Claude Code with proxy..."
    echo "Type a message and watch mitmproxy output"
    echo ""
    HTTP_PROXY=$PROXY HTTPS_PROXY=$PROXY NODE_TLS_REJECT_UNAUTHORIZED=0 claude

elif [ "$1" == "otto" ]; then
    echo "Starting otto with proxy..."
    echo "Type a message and watch mitmproxy output"
    echo ""
    cd "$(dirname "$0")/.."
    HTTP_PROXY=$PROXY HTTPS_PROXY=$PROXY NODE_TLS_REJECT_UNAUTHORIZED=0 bun run dev:cli

else
    echo "Usage: $0 [claude|otto]"
    echo ""
    echo "First, start mitmproxy in another terminal:"
    echo "  mitmproxy -s scripts/capture-anthropic.py -p 8080"
    echo ""
    echo "Then capture traffic:"
    echo "  $0 claude   # Capture real Claude Code traffic"
    echo "  $0 otto      # Capture otto spoofed traffic"
fi
