# Makefile for NeuroAgentTest (NAT) — Multi-Agent Neural Network Framework
# Usage: make <target>
# Run `make help` or just `make` to see all available targets.

VENV       := .venv
PYTHON     := $(VENV)/bin/python
PIP        := $(VENV)/bin/pip
PYTEST     := $(VENV)/bin/pytest
RUFF       := $(VENV)/bin/ruff
UVICORN    := $(VENV)/bin/uvicorn

IMAGE_NAME := ghcr.io/bg-playground/nat-engine
VERSION    ?= latest

.PHONY: help install test lint dev clean docker-build docker-run

# Default target
help:
	@echo ""
	@echo "NAT — NeuroAgentTest development workflow"
	@echo "=========================================="
	@echo ""
	@echo "Available targets:"
	@echo ""
	@echo "  make install       Create .venv and install package with dev dependencies"
	@echo "  make test          Run the full test suite (pytest tests/ -q)"
	@echo "  make lint          Run ruff linter and formatter checks"
	@echo "  make dev           Start a local development server with hot-reload"
	@echo "  make clean         Remove build artifacts, caches, and dist files"
	@echo "  make docker-build  Build the Docker image using Dockerfile"
	@echo "  make docker-run    Run the Docker container on port 8080"
	@echo "  make help          Show this help message (default)"
	@echo ""

install:
	@echo "→ Creating virtual environment at $(VENV)/ ..."
	python -m venv $(VENV)
	@echo "→ Installing package with dev dependencies ..."
	$(PIP) install --upgrade pip
	$(PIP) install -e ".[dev]"
	@echo "✓ Installation complete. Activate with: source $(VENV)/bin/activate"

test:
	@echo "→ Running test suite ..."
	$(PYTEST) tests/ -q

lint:
	@echo "→ Running ruff linter ..."
	$(RUFF) check src/ tests/
	@echo "→ Running ruff formatter check ..."
	$(RUFF) format --check src/ tests/
	@echo "✓ Lint checks passed."

dev:
	@echo "→ Starting NAT development server with hot-reload ..."
	$(UVICORN) mannf.product.server:app --reload --host 0.0.0.0 --port 8080

clean:
	@echo "→ Removing build artifacts and caches ..."
	find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name ".ruff_cache" -exec rm -rf {} + 2>/dev/null || true
	rm -rf dist/ build/
	@echo "✓ Clean complete."

docker-build:
	@echo "→ Building Docker image $(IMAGE_NAME):$(VERSION) ..."
	docker build -t $(IMAGE_NAME):$(VERSION) .
	@echo "✓ Docker image built: $(IMAGE_NAME):$(VERSION)"

docker-run:
	@echo "→ Running Docker container $(IMAGE_NAME):$(VERSION) on port 8080 ..."
	docker run --rm -p 8080:8080 $(IMAGE_NAME):$(VERSION)
