#!/usr/bin/env bash
# CCS - Claude Code Switch (Bootstrap)
# Delegates to Node.js implementation via npx
# https://github.com/kaitranntt/ccs
set -euo pipefail

readonly PACKAGE="@kaitranntt/ccs"
readonly MIN_NODE_VERSION=14

# Check Node.js installed
if ! command -v node &>/dev/null; then
    echo "[X] Node.js not found" >&2
    echo "    Install: https://nodejs.org (LTS recommended)" >&2
    exit 127
fi

# Check Node.js version (major only)
node_version=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
if [[ "$node_version" -lt "$MIN_NODE_VERSION" ]]; then
    echo "[X] Node.js $MIN_NODE_VERSION+ required (found: $(node -v))" >&2
    echo "    Update: https://nodejs.org" >&2
    exit 1
fi

# Check npm/npx available
if ! command -v npx &>/dev/null; then
    echo "[X] npx not found (requires npm 5.2+)" >&2
    exit 127
fi

# Execute via npx (auto-installs if needed)
exec npx "$PACKAGE" "$@"
