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
	find . | grep -E ".ruff_cache" | xargs rm -rf
	rm -f .coverage

venv: ## Makes the venv
	uv venv
	uv sync --all-extras

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

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

type: ## Run pyright
	uv run pyright

run: format test type ## Run all workflow

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

ENABLE_GPU   ?= true
ENABLE_AUDIO ?= true

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

# Auto-detection capabilities.
HAS_NVIDIA := $(shell which nvidia-smi > /dev/null 2>&1 && echo true || echo false)
HAS_PULSEAUDIO := $(shell pactl info > /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
ifeq ($(ENABLE_AUDIO),true)
  ifeq ($(HAS_PULSEAUDIO),true)
    COMPOSE_FILES += $(PULSEAUDIO_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))"
	@echo "  Audio: $(ENABLE_AUDIO) (detected: PulseAudio: $(HAS_PULSEAUDIO))"
	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
