#!/bin/bash
# ============================================================
#        CLAUDE CODE ON CURSOR - POWERED BY BAYONSTORE
# ============================================================
#  Server : https://bayonstore.com
#  Check  : https://bayonstore.com/check-key
# ============================================================

clear
echo ""
echo "============================================================"
echo "       CLAUDE CODE ON CURSOR - POWERED BY BAYONSTORE"
echo "============================================================"
echo ""
echo "  Server : https://bayonstore.com"
echo "  Check  : https://bayonstore.com/check-key"
echo ""
echo "============================================================"
echo ""

# Ask for the customer's API key
read -r -p "Enter your API Key (sk-...): " APIKEY

if [ -z "$APIKEY" ]; then
    echo ""
    echo "[ERROR] No API Key entered. Close this window and try again."
    echo ""
    read -r -n 1 -s
    exit 1
fi

# Point Claude Code at the BayonStore server (this session only)
export ANTHROPIC_BASE_URL="https://bayonstore.com"
export ANTHROPIC_AUTH_TOKEN="$APIKEY"
export ANTHROPIC_API_KEY="$APIKEY"
export ANTHROPIC_MODEL="bayon/claude-opus-4.8"
export ANTHROPIC_SMALL_FAST_MODEL="nghi/claude-haiku-4.5"

echo ""
echo "[OK] Configured. Opening Cursor..."
echo ""

# Launch Cursor with the environment applied. Prefer the 'cursor' CLI; fall back to open -a.
if command -v cursor >/dev/null 2>&1; then
    cursor .
elif [ -d "/Applications/Cursor.app" ]; then
    open -a "Cursor" .
else
    echo "[NOTE] Could not find Cursor. Install it, or add the 'cursor' command via"
    echo "       Cursor: Cmd+Shift+P -> 'Shell Command: Install cursor command in PATH'."
fi

echo ""
echo "============================================================"
echo "  Cursor has started. You can close this window."
echo "============================================================"
