.PHONY: help dev build run clean install-deps install-air test

# Default target
help:
	@echo "Goondex Development Commands:"
	@echo ""
	@echo "  make dev           - Start development server with live reload (Air)"
	@echo "  make build         - Build production binary"
	@echo "  make run           - Run production binary"
	@echo "  make clean         - Clean build artifacts"
	@echo "  make install-deps  - Install all dependencies"
	@echo "  make install-air   - Install Air for live reload"
	@echo "  make test          - Run tests"
	@echo ""

# Development with Air (live reload)
dev: install-air
	air

# Build production binary
build:
	@echo "Building Goondex..."
	@mkdir -p bin
	go build -o ./bin/goondex ./cmd/goondex
	@echo "Built: ./bin/goondex"

# Run production build
run: build
	./bin/goondex serve

# Clean build artifacts
clean:
	@echo "Cleaning build artifacts..."
	rm -rf tmp/
	rm -rf bin/
	rm -f build-errors.log
	@echo "Cleaned!"

# Install all dependencies
install-deps: install-air
	@echo "All dependencies installed!"

# Install Air for live reload
install-air:
	@if ! command -v air >/dev/null 2>&1; then \
		echo "Installing Air..."; \
		go install github.com/air-verse/air@latest; \
		echo "Air installed! Make sure ~/go/bin is in your PATH"; \
	else \
		echo "Air is already installed"; \
	fi

# Run tests
test:
	go test -v ./...

# Database migrations (if needed in future)
migrate-up:
	@echo "Running migrations..."
	# Add migration commands here

migrate-down:
	@echo "Rolling back migrations..."
	# Add rollback commands here
