#!/usr/bin/env bash

set -euo pipefail

script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
project_root="$(cd -- "${script_dir}/.." && pwd)"
hybrid_port="${PLOCAL_HYBRID_PORT:-8080}"

if [[ ! "${hybrid_port}" =~ ^[0-9]+$ ]] || (( hybrid_port < 1024 || hybrid_port > 65535 )); then
    echo "PLOCAL_HYBRID_PORT must be an integer from 1024 through 65535." >&2
    exit 2
fi

echo "PLOCAL hybrid server: http://127.0.0.1:${hybrid_port}"
echo "One national hub, four geography hubs, three Markets, eight Profiles, and six taxonomy pages are forwarded to Laravel (twenty-two routes)."
echo "The unpublished Florida and Miami geography hubs are explicitly denied."
echo "The legacy Construction Category URL redirects to its approved canonical taxonomy route."

exec php -S "127.0.0.1:${hybrid_port}" -t "${project_root}" "${script_dir}/plocal-hybrid-router.php"
