#!/usr/bin/env bash
# init.sh — First-time setup of SDD Framework framework in a consumer project.
#
# Usage:
#   bash scripts/init.sh
#   bash scripts/init.sh --module java-spring
#   bash scripts/init.sh --module java-spring --hooks
#
# What it does:
#   1. Copies framework files to .agent/ (commands, steps, hooks, rules, templates, modules)
#   2. Creates lightweight shortcut files in .claude/commands/ that delegate to .agent/
#   3. Writes .agent/FRAMEWORK_VERSION for upgrade.sh to track installed version
#
# After init:
#   - Commit .agent/ to git so the entire team shares the framework
#   - Run /setup-ai-first in Claude Code to complete project setup
#   - To upgrade later: bash scripts/upgrade.sh

set -euo pipefail

echo ""
echo "╔══════════════════════════════════════════╗"
echo "║   SDD Framework — Project Init            ║"
echo "╚══════════════════════════════════════════╝"
echo ""

# ── Prerequisite check ────────────────────────────────────────────────────────

if ! command -v node &> /dev/null; then
  echo "❌ Node.js is required. Install from https://nodejs.org"
  exit 1
fi

# ── Run installer via npx ─────────────────────────────────────────────────────

echo "Running: npx @educa-corp/sdd-framework --init $*"
echo ""

npx -y @educa-corp/sdd-framework --init "$@"

echo ""
echo "✅ Init complete!"
echo ""
echo "Recommended next steps:"
echo "  git add .agent/ .claude/commands/"
echo "  git commit -m 'chore: init spec-driven-docs framework'"
echo ""
echo "Then open Claude Code and run: /setup-ai-first"
echo ""
