#!/bin/bash
# description: Mark a plan as in-progress (rename __todo -> __wip)
# Args: <plan-filename>
# Output: new filename
set -euo pipefail

if [ "${OLLIE_BEADS_ENABLE:-0}" = "1" ] && command -v bd >/dev/null 2>&1 && [ -f ".beads" ]; then
    echo "error: beads is available — use 'bd' for planning instead of plan_start" >&2
    exit 2
fi

OLLIE="${OLLIE:-$HOME/mnt/ollie}"
PLAN_DIR="$OLLIE/pl"

[ $# -eq 1 ] || { echo "usage: plan_start <plan-filename>"; exit 1; }

SRC="$PLAN_DIR/$(basename "$1")"
[ -f "$SRC" ] || { echo "error: plan not found: $(basename "$1")"; exit 1; }

case "$SRC" in
    *__todo.md) ;;
    *) echo "error: plan is not tagged __todo: $(basename "$SRC")"; exit 1 ;;
esac

DST="${SRC/__todo.md/__wip.md}"
mv "$SRC" "$DST"
echo "$(basename "$DST")"
