#!/usr/bin/env bash
# Core — colors, logging, constants

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
RESET='\033[0m'

log()  { echo -e "${CYAN}[talent-scout]${RESET} $*"; }
ok()   { echo -e "${GREEN}✓${RESET} $*"; }
warn() { echo -e "${YELLOW}⚠${RESET} $*"; }
err()  { echo -e "${RED}✗${RESET} $*" >&2; }

POSTGRES_PORT="${DB_PORT:-25460}"
REDIS_PORT="${REDIS_PORT:-26399}"
API_PORT="${API_PORT:-3400}"
UI_PORT="${UI_PORT:-3401}"
LLM_PORT="${LLM_PORT:-8100}"
CAPTCHA_PORT="${CAPTCHA_PORT:-3099}"
MODEL_BOSS_REDIS_PORT="${MODEL_BOSS_REDIS_PORT:-26400}"
TOR_PORT=7710
MAILPIT_PORT=8025

POSTGRES_CONTAINER="lilith-talent-scout-postgres"
REDIS_CONTAINER="lilith-talent-scout-redis"

# Poll a URL until it responds or times out
# Usage: wait_http <label> <url> [timeout_seconds=60]
wait_http() {
  local label="$1" url="$2" timeout="${3:-60}"
  local elapsed=0
  log "Waiting for ${label}..."
  until curl -sf "$url" > /dev/null 2>&1; do
    sleep 2; elapsed=$((elapsed + 2))
    if [ "$elapsed" -ge "$timeout" ]; then
      err "${label} did not become ready within ${timeout}s"
      return 1
    fi
  done
  ok "${label} ready"
}
