.PHONY: help install install-ts install-py build lint lint-ts lint-py format format-py format-check format-check-py test clean run

# Default target - show help
help:
	@echo "Available commands:"
	@echo "  make install        - Install all dependencies (TypeScript and Python)"
	@echo "  make install-ts     - Install TypeScript dependencies only"
	@echo "  make install-py     - Install Python dependencies only"
	@echo "  make build          - Build TypeScript (type check)"
	@echo "  make lint           - Run all linters (TypeScript and Python)"
	@echo "  make lint-ts        - Run TypeScript linter only"
	@echo "  make lint-py        - Run Python linter only"
	@echo "  make format         - Format Python code"
	@echo "  make format-check   - Check Python formatting without modifying"
	@echo "  make test           - Run tests"
	@echo "  make clean          - Clean build artifacts and caches"
	@echo ""
	@echo "Running scripts:"
	@echo "  make run            - Interactive script runner (select language, category, script)"
	@echo "  make run-bash       - Run a bash script (e.g., make run-bash SCRIPT=bash/adb/push.sh)"

# Install all dependencies
install: install-ts install-py

# TypeScript dependencies
install-ts:
	cd typescript && pnpm install --frozen-lockfile

# Python dependencies
install-py:
	cd python && uv venv
	cd python && uv pip install -r requirements.txt

# Build TypeScript
build:
	cd typescript && pnpm exec tsc --noEmit

# Run all linters
lint: lint-ts lint-py

# TypeScript linting
lint-ts:
	cd typescript && pnpm exec eslint src --max-warnings 0

# Python linting
lint-py:
	cd python && uv run ruff check .

format-ts:
	cd typescript && pnpm exec eslint src --fix

# Format Python code
format: format-py

format-py:
	cd python && uv run ruff format .

# Check formatting without modifying
format-check: format-check-py

format-check-py:
	cd python && uv run ruff format --check .

# Run tests
test:
	@echo "No tests configured yet"
	@exit 0

# Clean build artifacts and caches
clean:
	rm -rf typescript/node_modules
	rm -rf python/.venv
	rm -rf python/.ruff_cache
	find python -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
	find python -type f -name "*.pyc" -delete 2>/dev/null || true

# Interactive script runner
run:
	@./run.sh

# Run a specific bash script
run-bash:
	@if [ -z "$(SCRIPT)" ]; then \
		echo "Please specify a script: make run-bash SCRIPT=bash/adb/push.sh"; \
		exit 1; \
	fi
	@if [ ! -f "$(SCRIPT)" ]; then \
		echo "Script not found: $(SCRIPT)"; \
		exit 1; \
	fi
	@echo "Running bash script: $(SCRIPT)"
	@op run --env-file=prod.env --no-masking -- bash "$(SCRIPT)"