#!/usr/bin/env bash
# Spustí backfill OTE cen uvnitř kontejneru backend (asyncpg tam už je v image).
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
if [[ -f "$HERE/../docker-compose.yml" ]]; then
  # Git checkout: repo/deploy/run_*.sh → compose v kořeni repa
  COMPOSE_DIR="$(cd "$HERE/.." && pwd)"
elif [[ -f "$HERE/../../docker-compose.yml" ]]; then
  # Produkce: /opt/ems-deploy/app/deploy/run_*.sh → compose v /opt/ems-deploy
  COMPOSE_DIR="$(cd "$HERE/../.." && pwd)"
else
  echo "Nenašel jsem docker-compose.yml (nadřazený adresář deploy/ nebo app/)." >&2
  echo "Spusťte ručně z kořene stacku: docker compose exec -T backend python3 scripts/backfill_ote_prices.py …" >&2
  exit 1
fi
cd "$COMPOSE_DIR"
exec docker compose exec -T backend python3 scripts/backfill_ote_prices.py "$@"
