#!/usr/bin/env bash
#
# Copy the canonical Freshdesk React Native integration skill into every
# tool-specific location inside this kit, and into the dev-repo Cursor alias.
#
# Edit only:
#   ai/skills/freshdesk-react-native-integration/SKILL.md
#
# Then run:
#   ./sync.sh
#
set -euo pipefail

ROOT="$(cd "$(dirname "$0")" && pwd)"
CANONICAL="$ROOT/ai/skills/freshdesk-react-native-integration/SKILL.md"
REPO_ROOT="$(cd "$ROOT/../.." && pwd)"
DEV_CURSOR_ALIAS="$REPO_ROOT/.cursor/skills/integrate-app-with-freshdesk-sdk/SKILL.md"

if [ ! -f "$CANONICAL" ]; then
  echo "Canonical skill not found: $CANONICAL" >&2
  exit 1
fi

copy_skill() {
  local dest="$1"
  mkdir -p "$(dirname "$dest")"
  cp "$CANONICAL" "$dest"
  echo "synced -> $dest"
}

copy_skill "$ROOT/AGENTS.md"
copy_skill "$ROOT/CLAUDE.md"
copy_skill "$ROOT/.cursor/skills/freshdesk-react-native-integration/SKILL.md"
copy_skill "$ROOT/.github/instructions/freshdesk-react-native-integration.instructions.md"
copy_skill "$ROOT/.kiro/steering/freshdesk-react-native-integration.md"

if [ -d "$(dirname "$DEV_CURSOR_ALIAS")" ]; then
  copy_skill "$DEV_CURSOR_ALIAS"
else
  echo "skip dev alias (missing $(dirname "$DEV_CURSOR_ALIAS"))"
fi

echo "Done. Canonical source: $CANONICAL"
