#!/usr/bin/env bash
#
# The `video-mode` machine action: whether the companion application offers a
# screen for watching what the webcam captured.
#
#   on    the phones show the evening's recordings
#   off   they do not
#
# **This is not whether the machine records.** A camera plugged into the kiosk
# records every song, always, whatever this is set to - the recording is the
# memory of the evening and the watching is a choice of mood. Somebody who
# turns the screen off on Saturday still wants Friday's clip on Sunday, and a
# setting that silently threw the evening away would be the one setting in
# this project that loses something.
#
# So there is nothing to start and nothing to stop here: the value is written
# down, the service reads it back on the next poll, and the phones draw one
# screen more or one screen fewer.

set -euo pipefail

# The shared half of the actions. The runner never sees this directory: it
# executes names out of the actions directory beside it, and a library among
# them would be a name somebody could ask for.
ARCHSTAR_ACTIONS_LIB="${ARCHSTAR_ACTIONS_LIB:-/usr/lib/archstar-actions/lib/common.sh}"
# The path is a runtime one and the linter reads these on standard input, so
# it could not follow it even if it were spelled literally.
# shellcheck source=/dev/null
source "${ARCHSTAR_ACTIONS_LIB}"

value="${1:-}"
require_one_of "${value}" on off

remember_setting video-mode "${value}"

if [[ "${value}" == 'on' ]]; then
    printf 'the phones can watch the evening; the camera was already recording it\n'
else
    printf 'the phones show no recordings; the camera keeps recording all the same\n'
fi
