#!/usr/bin/env bash
# El problema en el Tinkuy inicial: levanta la copia de build/tinkuy con su
# pasarela (puertos 3100 y 4100), corre make oversell y lo detiene todo.
# No modifica el Tinkuy del curso.
set -euo pipefail

cd build/tinkuy
export PORT=3100 GATEWAY_PORT=4100 GATEWAY_URL=http://localhost:4100 BASE_URL=http://localhost:3100 TINKUY_LOG=off
make --no-print-directory db
node tools/fake-gateway.ts > ../tinkuy-gateway.log 2>&1 &
gateway=$!
node src/main.ts > ../tinkuy-server.log 2>&1 &
server=$!
trap 'kill "$gateway" "$server" 2>/dev/null || true' EXIT
until curl -s -o /dev/null "$BASE_URL/health"; do sleep 0.1; done
make --no-print-directory oversell
