set dotenv-load := false
set positional-arguments := false

default:
	@just --list

install:
	@echo "→ Installing Go module dependencies…"
	go mod tidy
	go mod download

uninstall:
	@echo "→ Removing ./bin…"
	rm -rf bin

# Run the server in dev mode
run:
	go run ./cmd/server

build:
	@echo "→ Building for production…"
	@mkdir -p bin
	go build -ldflags="-s -w" -o bin/nuntius ./cmd/server

test:
	@echo "→ Running all tests…"
	go test -race -count=1 ./...
	@echo "→ Checking coverage threshold (≥80% for internal + pkg)…"
	go test -coverprofile=coverage.out ./internal/... ./pkg/...
	@go tool cover -func=coverage.out | grep '^total:' | python3 -c "import sys; pct=float(sys.stdin.read().split()[2].rstrip('%')); sys.exit(0 if pct >= 80 else 1)" && echo "Coverage ✓" || (echo "ERROR: coverage < 80%"; exit 1)
	@rm -f coverage.out

# Format Go source files
fmt:
	gofmt -w cmd internal pkg
