#!/bin/bash
# ============================================================
#        CLAUDE CODE ON VS CODE - POWERED BY BAYONSTORE
# ============================================================
#  Server : https://bayonstore.com
#  Check  : https://bayonstore.com/check-key
# ============================================================

clear
echo ""
echo "============================================================"
echo "       CLAUDE CODE ON VS CODE - 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="nghi/claude-opus-4.8"
export ANTHROPIC_SMALL_FAST_MODEL="bayon/claude-haiku-4.5"

echo ""
echo "[OK] Configured. Opening VS Code..."
echo ""

# Launch VS Code with the environment applied. Prefer the 'code' CLI; fall back to open -a.
if command -v code >/dev/null 2>&1; then
    code .
elif [ -d "/Applications/Visual Studio Code.app" ]; then
    open -a "Visual Studio Code" .
else
    echo "[NOTE] Could not find VS Code. Install it, or add the 'code' command via"
    echo "       VS Code: Cmd+Shift+P -> 'Shell Command: Install code command in PATH'."
fi

echo ""
echo "============================================================"
echo "  VS Code has started. You can close this window."
echo "============================================================"
