.PHONY: help install install-dev test test-cov format lint type-check clean build upload docs run-server run-examples

help:
	@echo "RAMJET - Distributed Cache for PyTorch Training"
	@echo ""
	@echo "Available targets:"
	@echo "  install        - Install package"
	@echo "  install-dev    - Install package with dev dependencies"
	@echo "  test           - Run tests"
	@echo "  test-cov       - Run tests with coverage"
	@echo "  format         - Format code with black and isort"
	@echo "  lint           - Run linters (flake8)"
	@echo "  type-check     - Run type checker (mypy)"
	@echo "  clean          - Clean build artifacts"
	@echo "  build          - Build distribution packages"
	@echo "  upload         - Upload to PyPI (requires credentials)"
	@echo "  docs           - Generate documentation"
	@echo "  run-server     - Start test cache servers (3 nodes)"
	@echo "  run-examples   - Run all example scripts"

install:
	pip install -e .

install-dev:
	pip install -e ".[dev]"
	pre-commit install

test:
	pytest tests/

test-cov:
	pytest --cov=ramjet --cov-report=html --cov-report=term tests/

format:
	black ramjet tests examples
	isort ramjet tests examples

lint:
	flake8 ramjet tests examples --max-line-length=120 --extend-ignore=E203,W503

type-check:
	mypy ramjet --ignore-missing-imports

clean:
	rm -rf build/
	rm -rf dist/
	rm -rf *.egg-info
	rm -rf htmlcov/
	rm -rf .pytest_cache/
	rm -rf .mypy_cache/
	find . -type d -name __pycache__ -exec rm -rf {} +
	find . -type f -name "*.pyc" -delete

build: clean
	python -m build

upload: build
	python -m twine upload dist/*

docs:
	@echo "Documentation is in markdown files:"
	@echo "  - README.md"
	@echo "  - QUICKSTART.md"
	@echo "  - INSTALLATION.md"
	@echo "  - PROJECT_STRUCTURE.md"
	@echo "  - CONTRIBUTING.md"

run-server:
	@echo "Starting 3 cache server nodes..."
	@echo "Node 1: http://localhost:9000"
	@echo "Node 2: http://localhost:9001"
	@echo "Node 3: http://localhost:9002"
	@echo ""
	@echo "Press Ctrl+C to stop all servers"
	@trap 'kill 0' SIGINT; \
	ramjet-server --port 9000 --storage-path /tmp/ramjet_cache_0 --capacity 1GB & \
	ramjet-server --port 9001 --storage-path /tmp/ramjet_cache_1 --capacity 1GB & \
	ramjet-server --port 9002 --storage-path /tmp/ramjet_cache_2 --capacity 1GB & \
	wait

run-examples:
	@echo "Running basic usage example..."
	python examples/basic_usage.py
	@echo ""
	@echo "Running PyTorch DataLoader example..."
	python examples/pytorch_dataloader.py
	@echo ""
	@echo "Running checkpoint caching example..."
	python examples/checkpoint_caching.py
