#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PLATFORM="$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)"

case "$PLATFORM" in
    darwin-arm64) BINARY="ch-search-darwin-arm64" ;;
    darwin-x86_64) BINARY="ch-search-darwin-amd64" ;;
    linux-x86_64) BINARY="ch-search-linux-amd64" ;;
    linux-aarch64) BINARY="ch-search-linux-arm64" ;;
    *) echo "Unsupported platform: $PLATFORM" >&2; exit 1 ;;
esac

SEARCH_BIN="$SCRIPT_DIR/bin/$BINARY"

if [ ! -x "$SEARCH_BIN" ]; then
    echo "Search binary not found: $SEARCH_BIN" >&2
    exit 1
fi

exec "$SEARCH_BIN" "$@"
