#!/usr/bin/env bash
set -euo pipefail

BASE_URL="https://bot.ahvclaw.com/downloads/telegram-cli-bot-setup"
ZIP_URL="$BASE_URL/telegram-cli-bot-setup-v3.zip?v=$(date +%s)"
TMP_DIR="$(mktemp -d)"
cleanup(){ rm -rf "$TMP_DIR"; }
trap cleanup EXIT

if [ "$(uname -s)" != "Darwin" ]; then
  echo "[ERROR] This installer is for macOS only."
  exit 1
fi

cd "$TMP_DIR"
echo "== AHV CLI Bot macOS installer =="
curl -fL "$ZIP_URL" -o setup.zip

if command -v ditto >/dev/null 2>&1; then
  ditto -x -k setup.zip .
elif command -v unzip >/dev/null 2>&1; then
  unzip -q setup.zip
else
  echo "[ERROR] Need ditto or unzip"
  exit 1
fi

chmod +x install-bots-macos.sh
./install-bots-macos.sh
