GO ?= go
BINARY ?= clinic
BIN_DIR ?= bin
CMD_PATH ?= ./cmd/clinic

.DEFAULT_GOAL := build

.PHONY: build install test legibility-check verify clean help

build: ## Build clinic binary under bin/
	@mkdir -p "$(BIN_DIR)"
	$(GO) build -o "$(BIN_DIR)/$(BINARY)" $(CMD_PATH)

install: build ## Build clinic and install it to GOPATH/bin
	@GOPATH_BIN="$$( $(GO) env GOPATH )/bin"; \
		mkdir -p "$$GOPATH_BIN"; \
		cp "$(BIN_DIR)/$(BINARY)" "$$GOPATH_BIN/$(BINARY)"

test: ## Run all go tests
	$(GO) test ./... -v

legibility-check: ## Validate agent-facing repository docs and structure
	./scripts/check-agent-legibility.sh

verify: legibility-check test ## Run repository checks expected before merge

clean: ## Remove local build artifacts
	rm -rf "$(BIN_DIR)"

help: ## Show available targets
	@echo "Targets:"
	@echo "  make build  - build $(BIN_DIR)/$(BINARY)"
	@echo "  make install - build and copy $(BINARY) to \$$(go env GOPATH)/bin"
	@echo "  make test   - run go test ./... -v"
	@echo "  make legibility-check - validate AGENTS/docs structure"
	@echo "  make verify - run legibility checks + tests"
	@echo "  make clean  - remove $(BIN_DIR)"
	@echo "  make help   - show this message"
