#!/usr/bin/env bash
# Regenerate protobuf Go stubs.
# Requires: buf, protoc-gen-go, protoc-gen-go-grpc on $PATH.
set -euo pipefail

cd "$(dirname "$0")/.."

if ! command -v buf >/dev/null 2>&1; then
    echo "error: buf not on PATH" >&2
    echo "install: go install github.com/bufbuild/buf/cmd/buf@latest" >&2
    exit 1
fi

echo ">> buf lint"
buf lint

echo ">> buf generate"
buf generate

echo ">> tidy go modules"
for dir in proto controller agent; do
    (cd "$dir" && go mod tidy)
done

echo ">> done"
