# lf_mri_platform — unified microservice stack
# Requires: Docker Desktop with Compose v2, GNU make (or nmake on Windows)
#
# Usage:
#   make plug          — start all services in stub mode (no hardware)
#   make real          — start all services in real mode (live hardware)
#   make down          — stop and remove containers
#   make logs          — tail logs from all services
#   make health        — check all service health endpoints
#   make restart svc=orchestrator  — restart a single service

.PHONY: up down plug real logs health restart build ps

ENV_FILE := .env

# ── Startup targets ──────────────────────────────────────────────────────────

up: $(ENV_FILE)
	docker compose --env-file $(ENV_FILE) up --build -d

plug: $(ENV_FILE)
	ORCHESTRATOR_MODE=plug docker compose --env-file $(ENV_FILE) up --build -d

real: $(ENV_FILE)
	ORCHESTRATOR_MODE=real docker compose --env-file $(ENV_FILE) up --build -d

down:
	docker compose down

build:
	docker compose --env-file $(ENV_FILE) build

# ── Monitoring ───────────────────────────────────────────────────────────────

logs:
	docker compose logs -f

ps:
	docker compose ps

restart:
	docker compose restart $(svc)

# ── Health checks ────────────────────────────────────────────────────────────

health:
	@echo "orchestrator  :" && curl -sf http://localhost:$${ORCHESTRATOR_PORT:-1717}/health  || echo "OFFLINE"
	@echo "seq-interp    :" && curl -sf http://localhost:$${SEQ_INTERP_PORT:-7475}/health    || echo "OFFLINE"
	@echo "spectrometer  :" && curl -sf http://localhost:$${SPECTROMETER_PORT:-8000}/api/    || echo "OFFLINE"
	@echo "reconstructor :" && curl -sf http://localhost:$${RECONSTRUCTOR_PORT:-8081}/health || echo "OFFLINE"
	@echo "spectroscopy  :" && curl -sf http://localhost:$${SPECTROSCOPY_PORT:-8002}/health  || echo "OFFLINE"

# ── Bootstrap ────────────────────────────────────────────────────────────────

$(ENV_FILE):
	@echo "Creating .env from .env.example..."
	cp .env.example $(ENV_FILE)
