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

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
STACK_DIR="$ROOT_DIR/local/docker-jitsi-meet"

if ! command -v docker >/dev/null 2>&1; then
    echo "Docker is not installed or not available in PATH. Install Docker Desktop, start it, then rerun this script."
    exit 1
fi

if ! docker compose version >/dev/null 2>&1; then
    echo "Docker Compose v2 is not available. Install/update Docker Desktop, then rerun this script."
    exit 1
fi

if [[ ! -d "$STACK_DIR" ]]; then
    "$SCRIPT_DIR/local-jitsi-setup.sh"
fi

"$SCRIPT_DIR/local-jitsi-sync.sh"

cd "$STACK_DIR"
docker compose up -d

echo "Local PoliticTalk Jitsi is starting."
echo "Open: https://localhost:8443/pt-local-test"
