#!/bin/bash
# install.sh for adom-tts (app).
# Runs from the extracted module directory (~/project/adom_modules/adom-tts/).
set -euo pipefail

DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DIR"

# 1) Binary onto PATH — ships INSIDE this per-platform package (the wiki
# resolves packages per platform; releases are only for artifacts fetched
# outside the install flow, which adom-tts does not have).
BIN_DIR="${HOME}/.local/bin"
mkdir -p "$BIN_DIR"
install -m 0755 "$DIR/bin/adom-tts" "$BIN_DIR/adom-tts"
echo "Installed adom-tts -> $BIN_DIR/adom-tts"

# 2) Claude Code skill (user tier only — dev/publish skills stay in source).
SKILL_DIR="${HOME}/.claude/skills"
for s in adom-tts tts-pronunciation; do
  if [ -f "$DIR/skills/$s/SKILL.md" ]; then
    mkdir -p "$SKILL_DIR/$s"
    install -m 0644 "$DIR/skills/$s/SKILL.md" "$SKILL_DIR/$s/SKILL.md"
    echo "Installed skill -> $SKILL_DIR/$s/SKILL.md"
  fi
done

# 3) Bash completion (best-effort, non-fatal).
if [ -f "$DIR/completions/adom-tts.bash" ]; then
  COMP_DIR="${HOME}/.bash_completion.d"
  mkdir -p "$COMP_DIR"
  install -m 0644 "$DIR/completions/adom-tts.bash" "$COMP_DIR/adom-tts" || true
fi

echo
echo "adom-tts installed. Verify the shared voice service is reachable:"
echo "  adom-tts health"
echo "Then try drive mode:"
echo "  adom-tts say \"Read me your last answer, I'm driving.\" --out /tmp/x.mp3 --play"
