# ============================================================
# OCDP root orchestration Makefile
# ============================================================

SHELL := /bin/bash

COMPOSE_BIN ?= docker compose
ROOT_COMPOSE := docker-compose.yml
COMPOSE := $(COMPOSE_BIN) -f $(ROOT_COMPOSE)

.PHONY: help install run-2 clean-2 docker-dev docker-prod docker-up docker-down docker-logs docker-ps test

.DEFAULT_GOAL := help

help:
	@echo ""
	@echo "OCDP commands"
	@echo "────────────────────────────────────────"
	@echo "  make install      Install local Go / frontend dependencies"
	@echo "  make run-2        Build and start full Docker Compose stack in background"
	@echo "  make docker-dev   Alias of run-2, kept for old docs / muscle memory"
	@echo "  make docker-prod  Alias of run-2"
	@echo "  make docker-up    Alias of run-2"
	@echo "  make docker-down  Stop containers, keep volumes"
	@echo "  make clean-2      Stop containers and remove project volumes"
	@echo "  make docker-logs  Follow Compose logs"
	@echo "  make docker-ps    Show Compose service status"
	@echo "  make test         Run structured verification script"
	@echo ""
	@echo "Default local ports: web=18080, https=18443, backend=18081, postgres=15432"
	@echo "Override with WEB_HTTP_PORT / WEB_HTTPS_PORT / BACKEND_PORT / POSTGRES_PORT."
	@echo ""

install:
	@echo "→ Downloading backend modules"
	@cd backend && go mod download
	@echo "→ Installing frontend dependencies"
	@cd frontend && npm ci

run-2:
	@echo "→ Building and starting OCDP stack"
	@$(COMPOSE) up --build -d postgres backend nginx
	@echo ""
	@$(COMPOSE) ps
	@echo ""
	@echo "Web:     http://localhost:$${WEB_HTTP_PORT:-18080}"
	@echo "Backend: http://localhost:$${BACKEND_PORT:-18081}/health"

docker-dev: run-2

docker-prod: run-2

docker-up: run-2

docker-down:
	@$(COMPOSE) down --remove-orphans

clean-2:
	@$(COMPOSE) down -v --remove-orphans

docker-logs:
	@$(COMPOSE) logs -f

docker-ps:
	@$(COMPOSE) ps

test:
	@test/readme-deployment-refresh.sh
