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

if [[ $# -ne 1 ]]; then
  echo "usage: $0 <cycle-slug>" >&2
  exit 1
fi

slug="$1"
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cycle_dir="$root/cycles/$slug"

if [[ -e "$cycle_dir" ]]; then
  echo "cycle already exists: $cycle_dir" >&2
  exit 1
fi

mkdir -p "$cycle_dir"
cp "$root/templates/00-user-spec.md" "$cycle_dir/00-user-spec.md"
cp "$root/templates/05-status.md" "$cycle_dir/05-status-v1.md"
cp "$root/templates/10-research-brief.md" "$cycle_dir/10-research-brief.md"
cp "$root/templates/20-architecture-brief.md" "$cycle_dir/20-architecture-brief.md"
cp "$root/templates/30-outline.md" "$cycle_dir/30-outline.md"
cp "$root/templates/40-draft.md" "$cycle_dir/40-draft-v1.md"
mkdir -p "$cycle_dir/50-reviews-v1"
cp "$root/templates/50-review-security.md" "$cycle_dir/50-reviews-v1/security.md"
cp "$root/templates/50-review-software.md" "$cycle_dir/50-reviews-v1/software.md"
cp "$root/templates/50-review-architecture.md" "$cycle_dir/50-reviews-v1/architecture.md"
cp "$root/templates/50-review-ietf-senior.md" "$cycle_dir/50-reviews-v1/ietf-senior.md"
cp "$root/templates/55-review-synthesis.md" "$cycle_dir/55-review-synthesis-v1.md"
cp "$root/templates/60-revision-plan.md" "$cycle_dir/60-revision-plan-v1.md"

echo "created $cycle_dir"
