help:  ## Show help
	@grep -E '^[.a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

clean: ## Clean autogenerated files
	rm -rf dist
	find . -type f -name "*.DS_Store" -ls -delete
	find . | grep -E "(__pycache__|\.pyc|\.pyo)" | xargs rm -rf
	find . | grep -E ".pytest_cache" | xargs rm -rf
	find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
	rm -f .coverage

venv: ## Make virtual environment
	uv venv
	uv sync --all-extras

format: ## Run pre-commit hooks
	uv run pre-commit run -a

test: ## Run tests
	uv run pytest -v --cov

type: ## Run type check
	uv run pyright

run: format test type ## Run all workflow.

# -----------------
#  Docker Settings
# -----------------

ENABLE_GPU   ?= true

# Compose files
BASE_COMPOSE  := -f docker-compose.yml
NVIDIA_COMPOSE   := -f docker-compose.nvidia.yml

# Auto-detection capabilities.
HAS_NVIDIA := $(shell which nvidia-smi > /dev/null 2>&1 && echo true || echo false)

# -f options
COMPOSE_FILES := $(BASE_COMPOSE)
ifeq ($(ENABLE_GPU),true)
  ifeq ($(HAS_NVIDIA),true)
    COMPOSE_FILES += $(NVIDIA_COMPOSE)
  endif
endif

docker-build: ## Build docker images
	docker compose $(BASE_COMPOSE) build --no-cache

docker-up: ## Start docker containers (ENABLE_GPU=false to disable GPU, ENABLE_AUDIO=false to disable audio)
	@echo "→ Starting dev container"
	@echo "  GPU: $(ENABLE_GPU) (detected: NVIDIA: $(HAS_NVIDIA))"
	docker compose $(COMPOSE_FILES) up -d

docker-down: ## Stop docker containers
	docker compose $(BASE_COMPOSE) down

docker-down-volume:  ## Stop docker containers with removing volumes.
	docker compose $(BASE_COMPOSE) down -v

docker-attach: ## Attach to development container
	docker compose $(BASE_COMPOSE) exec dev bash

# ------------------------
# Documentation Workflows
# ------------------------

docs-build: ## Build documentation
	uv run mkdocs build

docs-serve: ## Serve documentation locally
	uv run mkdocs serve

docs-deploy: ## Deploy documentation to GitHub Pages
	uv run mkdocs gh-deploy --force
