.PHONY: build up down restart logs logs-backend logs-frontend clean shell-backend status prune release help install

# Prefer Docker Compose V2 plugin, fallback to docker-compose
COMPOSE := $(shell if docker compose version >/dev/null 2>&1; then echo "docker compose"; elif command -v docker-compose >/dev/null 2>&1; then echo "docker-compose"; else echo "docker-compose"; fi)

# ── Build / Run ─────────────────────────────────────────────
build:
	$(COMPOSE) build --no-cache

up:
	$(COMPOSE) up -d

down:
	$(COMPOSE) down

restart:
	$(COMPOSE) restart

# ── Logs ────────────────────────────────────────────────────
logs:
	$(COMPOSE) logs -f

logs-backend:
	$(COMPOSE) logs -f backend

logs-frontend:
	$(COMPOSE) logs -f frontend

# ── Debug ───────────────────────────────────────────────────
shell-backend:
	$(COMPOSE) exec backend bash

status:
	$(COMPOSE) ps

# ── Cleanup ─────────────────────────────────────────────────
clean:
	$(COMPOSE) down -v --rmi all --remove-orphans

prune:
	docker system prune -f

# ── Ubuntu one-click ────────────────────────────────────────
install:
	./install-ubuntu.sh

# ── Pack release/ + release.tar.gz ──────────────────────────
release:
	./scripts/pack-release.sh

help:
	@echo "make build | up | down | restart | logs | status | clean | install | release"
