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

if [[ $# -lt 2 || $# -gt 3 ]]; then
  echo "usage: $0 <cycle-slug> <role> [version]" >&2
  exit 1
fi

slug="$1"
role="$2"
version="${3:-1}"
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cycle_dir="$root/cycles/$slug"

if [[ ! -d "$cycle_dir" ]]; then
  echo "missing cycle: $cycle_dir" >&2
  exit 1
fi

case "$role" in
  researcher)
    printf '%s\n' "$cycle_dir/10-research-brief.md"
    ;;
  architect)
    printf '%s\n%s\n' "$cycle_dir/20-architecture-brief.md" "$cycle_dir/30-outline.md"
    ;;
  author)
    printf '%s\n' "$cycle_dir/40-draft-v$version.md"
    ;;
  security-reviewer)
    printf '%s\n' "$cycle_dir/50-reviews-v$version/security.md"
    ;;
  software-reviewer)
    printf '%s\n' "$cycle_dir/50-reviews-v$version/software.md"
    ;;
  architecture-reviewer)
    printf '%s\n' "$cycle_dir/50-reviews-v$version/architecture.md"
    ;;
  ietf-senior-reviewer)
    printf '%s\n' "$cycle_dir/50-reviews-v$version/ietf-senior.md"
    ;;
  review-lead)
    printf '%s\n%s\n' "$cycle_dir/55-review-synthesis-v$version.md" "$cycle_dir/60-revision-plan-v$version.md"
    ;;
  *)
    echo "unknown role: $role" >&2
    exit 1
    ;;
esac
