#!/usr/bin/env bash
# SEO Audit Skill Pack — macOS/Linux installer
# Installs the /seo-audit orchestrator into Claude Code's user-level skills directory.
set -euo pipefail

SKILL_SOURCE="$(dirname "$0")/skills/seo-audit"
SKILLS_DIR="$HOME/.claude/skills"
SKILL_DEST="$SKILLS_DIR/seo-audit"

if [ ! -f "$SKILL_SOURCE/SKILL.md" ]; then
  echo "Error: skill source not found: $SKILL_SOURCE (run this from the skill-pack folder)"
  exit 1
fi

echo "Installing the /seo-audit orchestrator..."

# Back up any existing seo-audit skill before overwriting (the orchestrator supersedes it).
if [ -f "$SKILL_DEST/SKILL.md" ]; then
  cp "$SKILL_DEST/SKILL.md" "$SKILL_DEST/SKILL.md.bak"
  echo "  Backed up existing seo-audit skill -> $SKILL_DEST/SKILL.md.bak"
fi

mkdir -p "$SKILL_DEST"
cp "$SKILL_SOURCE/SKILL.md" "$SKILL_DEST/SKILL.md"
echo "  Installed: $SKILL_DEST"

# Check full dependency packages, including delivery-gating claim-check.
CHECKER="$(dirname "$0")/check-skills.py"
if [ ! -f "$CHECKER" ]; then
  echo "Download https://seo-audit-site.vercel.app/skill-pack/check-skills.py beside this installer, then rerun."
  exit 1
fi
if ! python3 "$CHECKER" --project "$PWD"; then
  echo "Orchestrator copied, but audit dependencies are incomplete. Follow the skill-pack installation commands; rerun the checker from your audit project."
  exit 1
fi
echo "Dependency files verified. Start a fresh Claude Code session in your audit project and confirm the selected skill paths before /seo-audit begin."
