.PHONY: help install dev build test docker-up docker-down docker-logs docker-ps docker-build docker-restart docker-test speech-up speech-down speech-logs clean matrix-up matrix-down matrix-logs matrix-setup-bot

# Default target
help:
	@echo "Mosaic Stack - Available commands:"
	@echo ""
	@echo "Development:"
	@echo "  make install          Install dependencies"
	@echo "  make dev              Start development servers"
	@echo "  make build            Build all applications"
	@echo "  make test             Run all tests"
	@echo "  make lint             Run linters"
	@echo "  make format           Format code"
	@echo ""
	@echo "Docker:"
	@echo "  make docker-up              Start Docker services (core)"
	@echo "  make docker-up-full         Start Docker services (all)"
	@echo "  make docker-up-traefik      Start with bundled Traefik"
	@echo "  make docker-down            Stop Docker services"
	@echo "  make docker-logs            View Docker logs"
	@echo "  make docker-ps              Show Docker service status"
	@echo "  make docker-build           Rebuild Docker images"
	@echo "  make docker-restart         Restart Docker services"
	@echo "  make docker-test            Run Docker smoke test"
	@echo "  make docker-test-traefik    Run Traefik integration tests"
	@echo ""
	@echo "Speech Services:"
	@echo "  make speech-up              Start speech services (STT + TTS)"
	@echo "  make speech-down            Stop speech services"
	@echo "  make speech-logs            View speech service logs"
	@echo ""
	@echo "Matrix Dev Environment:"
	@echo "  make matrix-up              Start Matrix services (Synapse + Element)"
	@echo "  make matrix-down            Stop Matrix services"
	@echo "  make matrix-logs            View Matrix service logs"
	@echo "  make matrix-setup-bot       Create bot account and get access token"
	@echo ""
	@echo "Database:"
	@echo "  make db-migrate       Run database migrations"
	@echo "  make db-seed          Seed development data"
	@echo "  make db-studio        Open Prisma Studio"
	@echo "  make db-reset         Reset database (WARNING: deletes data)"
	@echo ""
	@echo "Cleanup:"
	@echo "  make clean            Clean build artifacts"
	@echo "  make clean-all        Clean everything including node_modules"
	@echo "  make docker-clean     Remove Docker containers and volumes"

# Development
install:
	pnpm install

dev:
	pnpm dev

build:
	pnpm build

test:
	pnpm test

lint:
	pnpm lint

format:
	pnpm format

# Docker operations
docker-up:
	docker compose up -d

docker-up-full:
	docker compose --profile full up -d

docker-up-traefik:
	docker compose --profile traefik-bundled up -d

docker-down:
	docker compose down

docker-logs:
	docker compose logs -f

docker-ps:
	docker compose ps

docker-build:
	docker compose build

docker-restart:
	docker compose restart

docker-test:
	./scripts/test-docker-deployment.sh

docker-test-traefik:
	./tests/integration/docker/traefik.test.sh all

# Speech services
speech-up:
	docker compose -f docker-compose.yml -f docker-compose.speech.yml up -d speaches kokoro-tts

speech-down:
	docker compose -f docker-compose.yml -f docker-compose.speech.yml down --remove-orphans

speech-logs:
	docker compose -f docker-compose.yml -f docker-compose.speech.yml logs -f speaches kokoro-tts

# Matrix Dev Environment
matrix-up:
	docker compose -f docker/docker-compose.yml -f docker/docker-compose.matrix.yml up -d

matrix-down:
	docker compose -f docker/docker-compose.yml -f docker/docker-compose.matrix.yml down

matrix-logs:
	docker compose -f docker/docker-compose.yml -f docker/docker-compose.matrix.yml logs -f synapse element-web

matrix-setup-bot:
	docker/matrix/scripts/setup-bot.sh

# Database operations
db-migrate:
	cd apps/api && pnpm prisma:migrate

db-seed:
	cd apps/api && pnpm prisma:seed

db-studio:
	cd apps/api && pnpm prisma:studio

db-reset:
	cd apps/api && pnpm prisma:reset

# Cleanup
clean:
	pnpm clean

clean-all:
	pnpm clean
	rm -rf node_modules

docker-clean:
	docker compose down -v
	docker system prune -f
