# =============================================================================
# Presence Service - Makefile
# =============================================================================

.PHONY: help install build test test-unit test-integration test-e2e \
        test-docker-all docker-build docker-up docker-down clean lint format \
        prisma-generate prisma-migrate coverage

# Default target
help:
	@echo "Presence Service - Available commands:"
	@echo ""
	@echo "  Development:"
	@echo "    make install            Install dependencies"
	@echo "    make build              Build the project"
	@echo "    make lint               Run linter"
	@echo "    make format             Format code"
	@echo ""
	@echo "  Testing:"
	@echo "    make test               Run all tests"
	@echo "    make test-unit          Run unit tests only"
	@echo "    make test-integration   Run integration tests only"
	@echo "    make test-e2e           Run E2E tests (requires DB)"
	@echo "    make coverage           Run tests with coverage"
	@echo ""
	@echo "  Docker Testing:"
	@echo "    make docker-build       Build Docker images"
	@echo "    make docker-up          Start Docker containers"
	@echo "    make docker-down        Stop Docker containers"
	@echo "    make test-docker-all    Run all tests in Docker"
	@echo ""
	@echo "  Database:"
	@echo "    make prisma-generate    Generate Prisma client"
	@echo "    make prisma-migrate     Run Prisma migrations"
	@echo ""
	@echo "  Cleanup:"
	@echo "    make clean              Clean build artifacts"

# =============================================================================
# Development
# =============================================================================

install:
	npm install

build:
	npm run build

lint:
	npm run lint

format:
	npm run format

# =============================================================================
# Testing
# =============================================================================

test:
	npm test

test-unit:
	npm test -- --selectProjects unit

test-integration:
	npm test -- --selectProjects integration

test-e2e:
	npm test -- --selectProjects e2e

coverage:
	npm test -- --coverage

# =============================================================================
# Docker Testing
# =============================================================================

docker-build:
	docker-compose -f docker-compose.test.yml build

docker-up:
	docker-compose -f docker-compose.test.yml up -d

docker-down:
	docker-compose -f docker-compose.test.yml down -v

test-docker-all:
	docker-compose -f docker-compose.test.yml run --rm test npm test

# =============================================================================
# Database
# =============================================================================

prisma-generate:
	npx prisma generate

prisma-migrate:
	npx prisma migrate dev

prisma-migrate-deploy:
	npx prisma migrate deploy

# =============================================================================
# Cleanup
# =============================================================================

clean:
	rm -rf dist
	rm -rf coverage
	rm -rf node_modules/.cache
