# Detecta si existe 'docker compose' o 'docker-compose'
COMPOSE := $(shell if command -v "docker compose" >/dev/null 2>&1; \
                then echo "docker compose"; \
                else echo "docker-compose"; \
              fi)

# Define servicios
SERVICE_DEV       := dev
SERVICE_BUILD     := build-service
SERVICE_DEPLOY    := deployment

.PHONY: help dev build-service deployment publish-beta

help:
	@echo "Usage: make [target] [CACHE=true]"
	@echo
	@echo "Targets:"
	@echo "  dev           Start development service"
	@echo "  build-service Build the service locally"
	@echo "  deployment    Build and publish to NPM (production)"
	@echo
	@echo "Options for 'dev':"
	@echo "  CACHE=true    Recreate containers and rebuild images"

dev:
ifeq ($(CACHE),true)
	@echo "Starting development service with cache cleaning..."
	$(COMPOSE) up --build --force-recreate $(SERVICE_DEV)
else
	@echo "Starting development service without cache cleaning..."
	$(COMPOSE) up $(SERVICE_DEV)
endif

build-service:
	@echo "Building service locally..."
	$(COMPOSE) up --build --force-recreate $(SERVICE_BUILD)

publish-prod:
	@echo "Building and publishing to NPM (production)..."
	$(COMPOSE) up --build --force-recreate publish-prod

publish-beta:
	@echo "Building and publishing to NPM (beta tag)..."
	$(COMPOSE) up --build --force-recreate publish-beta
