.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)"

# 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