#!/bin/bash
# Log start of lunch break.
set -euo pipefail

F="$HOME/long-day-factory.json"
TS="$(python3 -c 'import datetime;print(datetime.datetime.now().astimezone().isoformat(timespec="seconds"))')"

if [ ! -f "$F" ]; then
  printf '{\n  "startTime": null,\n  "lunchTime": null,\n  "backToWork": null\n}\n' > "$F"
fi

tmp="$(mktemp)"
jq --arg ts "$TS" '.lunchTime = $ts' "$F" > "$tmp" && mv "$tmp" "$F"

echo "Lunch break started at $TS"

if [ "$(jq -r '.startTime' "$F")" = "null" ]; then
  echo "WARNING: startTime is not set — did you skip long-day-start this morning?"
fi
