#!/usr/bin/env bash
# Build: gap-night offer automation
# Creates a real automation on a gap_night trigger, so the offer goes out the moment a hole opens between bookings. The finder script tells you the gaps exist; this one works them without you.
#
# Category : Revenue
# Safety   : WRITES DATA, read before running
# Uses     : workflows create, workflows trigger-types, sms-templates list
# Returns  : A live workflow id, triggered natively on gap nights.
#
# Requires the SendSquared CLI and jq:
#   curl -fsSL https://cli.sendsquared.com/install.sh | bash
#   sendsquared auth login
#
# Free to use and adapt. https://sendsquared.com/cli/scripts/#build-gap-night-automation

# Build the gap-night offer automation. Run once.
# Usage: ./build-gap-night-automation.sh <smsTemplateId>
set -euo pipefail
TEMPLATE=${1:?pass an SMS template id, see: sendsquared sms-templates list}

STEPS=$(cat <<JSON
[
  { "type": "Wait", "value": "2h", "label": "Let the PMS settle before offering" },
  { "type": "Sms",  "value": $TEMPLATE, "label": "Offer the open night to the adjacent guest" }
]
JSON
)

sendsquared workflows create \
  --name "Gap night offer" \
  --description "Fires when a gap night opens next to an existing stay." \
  --trigger-type gap_night \
  --trigger-value gap_night.departure \
  --steps "$STEPS"

echo "Built. Review it in the app before enabling, then:"
echo "  sendsquared workflows list"
