.PHONY: test test-unit test-integration test-e2e test-cov test-docker test-docker-all clean

# Default test command
test:
	npm test

# Unit tests only
test-unit:
	npm run test:unit

# Integration tests only
test-integration:
	npm run test:integration

# E2E tests only
test-e2e:
	npm run test:e2e

# Run all tests with coverage
test-cov:
	npm run test:cov

# Run all tests locally
test-all:
	npm run test:all

# Docker-based tests
test-docker:
	docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit

test-docker-all:
	docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit authorization-service-test

# Clean up test containers
test-docker-clean:
	docker-compose -f docker-compose.test.yml down -v --remove-orphans

# Build the application
build:
	npm run build

# Lint the code
lint:
	npm run lint

# Format the code
format:
	npm run format

# Generate Prisma client
prisma-generate:
	npx prisma generate

# Run database migrations
prisma-migrate:
	npx prisma migrate dev

# Start development server
dev:
	npm run start:dev

# Start production server
start:
	npm run start:prod

# Clean build artifacts
clean:
	rm -rf dist coverage node_modules/.cache

# Install dependencies
install:
	npm ci && npx prisma generate

# Full CI pipeline
ci: install lint test-all build
	@echo "CI pipeline completed successfully"

# Help
help:
	@echo "Available targets:"
	@echo "  test              - Run all tests"
	@echo "  test-unit         - Run unit tests"
	@echo "  test-integration  - Run integration tests"
	@echo "  test-e2e          - Run E2E tests"
	@echo "  test-cov          - Run tests with coverage"
	@echo "  test-all          - Run all test suites"
	@echo "  test-docker       - Run tests in Docker"
	@echo "  test-docker-all   - Run all tests in Docker"
	@echo "  test-docker-clean - Clean up Docker test containers"
	@echo "  build             - Build the application"
	@echo "  lint              - Lint the code"
	@echo "  format            - Format the code"
	@echo "  dev               - Start development server"
	@echo "  start             - Start production server"
	@echo "  clean             - Clean build artifacts"
	@echo "  install           - Install dependencies"
	@echo "  ci                - Run full CI pipeline"
