.PHONY: help install build test test-unit test-integration test-e2e test-cov \
        docker-build docker-up docker-down docker-logs \
        test-docker-unit test-docker-integration test-docker-e2e test-docker-all \
        prisma-generate prisma-migrate prisma-studio clean

# Default target
help:
	@echo "Available commands:"
	@echo ""
	@echo "Development:"
	@echo "  make install            - Install dependencies"
	@echo "  make build              - Build the application"
	@echo "  make clean              - Clean build artifacts"
	@echo ""
	@echo "Testing (Local):"
	@echo "  make test               - Run all tests"
	@echo "  make test-unit          - Run unit tests"
	@echo "  make test-integration   - Run integration tests"
	@echo "  make test-e2e           - Run E2E tests"
	@echo "  make test-cov           - Run tests with coverage"
	@echo ""
	@echo "Docker:"
	@echo "  make docker-build       - Build Docker images"
	@echo "  make docker-up          - Start all services"
	@echo "  make docker-down        - Stop all services"
	@echo "  make docker-logs        - View logs"
	@echo ""
	@echo "Testing (Docker):"
	@echo "  make test-docker-unit   - Run unit tests in Docker"
	@echo "  make test-docker-integration - Run integration tests in Docker"
	@echo "  make test-docker-e2e    - Run E2E tests in Docker"
	@echo "  make test-docker-all    - Run all tests in Docker"
	@echo ""
	@echo "Prisma:"
	@echo "  make prisma-generate    - Generate Prisma client"
	@echo "  make prisma-migrate     - Run database migrations"
	@echo "  make prisma-studio      - Open Prisma Studio"

# Development
install:
	npm ci

build:
	npm run build

clean:
	rm -rf dist coverage node_modules/.cache

# Local Testing
test: test-unit

test-unit:
	npm test

test-integration:
	npm run test:integration

test-e2e:
	npm run test:e2e

test-cov:
	npm run test:cov

# Docker
docker-build:
	docker compose build

docker-up:
	docker compose up -d

docker-down:
	docker compose down -v

docker-logs:
	docker compose logs -f

# Docker Testing
test-docker-unit:
	docker compose -f docker-compose.test.yml up --build --abort-on-container-exit test-runner
	docker compose -f docker-compose.test.yml down -v

test-docker-integration:
	docker compose -f docker-compose.test.yml up --build --abort-on-container-exit integration-test-runner
	docker compose -f docker-compose.test.yml down -v

test-docker-e2e:
	docker compose -f docker-compose.test.yml up --build --abort-on-container-exit e2e-test-runner
	docker compose -f docker-compose.test.yml down -v

test-docker-all: test-docker-unit test-docker-integration test-docker-e2e

# Prisma
prisma-generate:
	npx prisma generate

prisma-migrate:
	npx prisma migrate dev

prisma-studio:
	npx prisma studio
