#!/usr/bin/env bash
# nerf-az-boards-mywi-comment -- Add a comment to a work item assigned to you
# Generated from az-boards manifest. Do not edit directly.
# nerf:threat:read=remote
# nerf:threat:write=remote

set -euo pipefail

_NERF_DRY_RUN=""

usage() {
  cat >&2 <<'EOF'
Usage: nerf-az-boards-mywi-comment <wi_id> <comment>

Arguments:
  <wi_id> (required)
      Work item ID (numeric, must be assigned to you)
      Must match: ^[0-9]+$
  <comment> (required)
      Comment text to add to the work item

Maps to: az boards work-item update --id <wi_id> --discussion <comment> --output none

Add a comment to a work item assigned to you.
EOF
  exit 1
}

while [[ $# -gt 0 ]]; do
  case "$1" in
    --nerf-dry-run) _NERF_DRY_RUN="true"; shift 1 ;;
    -h|--help) usage ;;
    --) shift; break ;;
    *) break ;;
  esac
done

WI_ID="${1:-}"
shift 2>/dev/null || true
COMMENT="${1:-}"
shift 2>/dev/null || true

if [[ -n "${WI_ID}" ]] && [[ "${WI_ID}" == -* ]]; then
  echo "error: nerf-az-boards-mywi-comment: <wi_id> cannot start with '-'" >&2
  echo "  hint: use -- before positional arguments if needed" >&2
  exit 1
fi

if [[ -z "${WI_ID}" ]]; then
  echo "error: nerf-az-boards-mywi-comment: missing required argument <wi_id>" >&2
  echo "  hint: provide a value for <wi_id>" >&2
  usage
fi

_NERF_PATTERN='^[0-9]+$'
if [[ -n "${WI_ID}" ]] && ! [[ "${WI_ID}" =~ $_NERF_PATTERN ]]; then
  echo "error: nerf-az-boards-mywi-comment: argument <wi_id> does not match required pattern" >&2
  echo "  value:   \"${WI_ID}\"" >&2
  echo "  pattern: ^[0-9]+$" >&2
  echo "  hint: value must match ^[0-9]+$" >&2
  exit 1
fi

if [[ -n "${COMMENT}" ]] && [[ "${COMMENT}" == -* ]]; then
  echo "error: nerf-az-boards-mywi-comment: <comment> cannot start with '-'" >&2
  echo "  hint: use -- before positional arguments if needed" >&2
  exit 1
fi

if [[ -z "${COMMENT}" ]]; then
  echo "error: nerf-az-boards-mywi-comment: missing required argument <comment>" >&2
  echo "  hint: provide a value for <comment>" >&2
  usage
fi

if [[ "$_NERF_DRY_RUN" == "true" ]]; then
  echo "dry-run: az boards work-item update --id "${WI_ID}" --discussion "${COMMENT}" --output none"
  exit 0
fi

exec az boards work-item update --id "${WI_ID}" --discussion "${COMMENT}" --output none
