# Makefile for acp-sdk-go
#
# Targets:
#   all        - build, fmt, and test everything
#   build      - compile all packages
#   fmt        - format all Go source files
#   vet        - run go vet
#   test       - run all tests (with race detector)
#   test-short - run tests without race detector
#   clean      - remove build artifacts
#   lint       - run golangci-lint (if installed)
#   gen        - download schema + regenerate schema/*.go
#   gen-schema - generate schema/*.go from local schema.json
#   gen-download - download schema.json and meta.json from GitHub

GO := go
GOFLAGS := -v
TESTFLAGS := -race -count=1
MOD := .

.PHONY: all build fmt vet test test-short clean lint install-tools gen gen-schema gen-download

all: build fmt vet test

## build compiles all packages.
build:
	$(GO) build $(GOFLAGS) ./...

## fmt formats all Go source files.
fmt:
	$(GO) fmt $(MOD)/...

## vet runs go vet with all checks.
vet:
	$(GO) vet ./...

## test runs all tests with the race detector.
test:
	$(GO) test $(TESTFLAGS) ./...

## test-short runs tests without the race detector.
test-short:
	$(GO) test -count=1 ./...

## clean removes build artifacts.
clean:
	$(GO) clean -cache
	rm -f $(MOD)/examples/*/acp-sdk-test-bin

## install-tools installs development dependencies.
install-tools:
	which golangci-lint || go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
	which staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest

## lint runs golangci-lint (must be installed separately).
lint:
	@which golangci-lint > /dev/null || (echo "install golangci-lint first: go install github.com/golangci-lint/cmd/golangci-lint@latest" && exit 1)
	golangci-lint run ./...

## e2e runs an end-to-end smoke test with the agent and client examples.
e2e: build
	@echo "Building examples..."
	$(GO) build -o /tmp/acp-sdk-test-agent ./examples/agent
	@echo "Running agent..."
	@echo "hello" | timeout 5 $(GO) run examples/client/main.go -- /tmp/acp-sdk-test-agent
	rm -f /tmp/acp-sdk-test-agent

## gen downloads the latest schema and regenerates all schema/*.go files.
gen:
	$(GO) run ./cmd/gen all

## gen-schema generates Go types from the local schema.json (no download).
gen-schema:
	$(GO) run ./cmd/gen schema

## gen-download downloads schema.json and meta.json from GitHub.
gen-download:
	$(GO) run ./cmd/gen download
