#!/usr/bin/env bash
set -euo pipefail

LABEL="${SOFIIA_LAUNCHD_LABEL:-com.daarion.sofiia}"
DOMAIN="gui/$(id -u)"
DATA_DIR_VALUE="${SOFIIA_DATA_DIR:-${HOME}/.sofiia/console-data}"
LOG_OUT="${DATA_DIR_VALUE}/logs/launchd.out.log"
LOG_ERR="${DATA_DIR_VALUE}/logs/launchd.err.log"

echo "[sofiia-launchd] domain: ${DOMAIN}"
echo "[sofiia-launchd] label: ${LABEL}"
echo ""
launchctl print "${DOMAIN}/${LABEL}" || true
echo ""
echo "[sofiia-launchd] tail stdout (${LOG_OUT})"
tail -n 50 "${LOG_OUT}" 2>/dev/null || true
echo ""
echo "[sofiia-launchd] tail stderr (${LOG_ERR})"
tail -n 100 "${LOG_ERR}" 2>/dev/null || true
