.PHONY: help fbs-go flatc-check

# Pinned flatc version. The committed Go bindings under <schema>/ and the
# flatbuffers Go runtime (go.mod) are on this version; the TS side mirrors
# it via `make -C ui fbs-ts`. Generating with a different flatc silently
# churns output and can flip nullable-scalar wire defaults, so fbs-go
# refuses to run on a mismatch. Distro packages (e.g. Debian's
# flatbuffers-compiler) are too old — use the release binary at $(FLATC_URL).
REQUIRED_FLATC := 25.9.23
FLATC_URL      := https://github.com/google/flatbuffers/releases/tag/v$(REQUIRED_FLATC)
# Every schema in this directory. Listed explicitly (not a wildcard) so a
# stray .fbs cannot silently change the generated set.
FBS_INPUTS     := common.fbs lobby.fbs user.fbs report.fbs order.fbs diplomail.fbs battle.fbs gateway.fbs notification.fbs

help:
	@echo "schema/fbs targets:"
	@echo "  fbs-go   FlatBuffers Go generation from *.fbs into <schema>/ (requires flatc $(REQUIRED_FLATC))"

flatc-check:
	@command -v flatc >/dev/null || { echo "flatc not found; install flatc $(REQUIRED_FLATC) from $(FLATC_URL) (distro packages such as Debian's flatbuffers-compiler are too old)"; exit 1; }
	@flatc --version | grep -q "$(REQUIRED_FLATC)" || { echo "flatc $(REQUIRED_FLATC) required; found '$$(flatc --version)'. Get the pinned binary from $(FLATC_URL)"; exit 1; }

# --go-module-name rewrites cross-namespace imports to the fully-qualified
# module path so the generated code links without local replace directives.
fbs-go: flatc-check
	flatc --go --go-module-name galaxy/schema/fbs $(FBS_INPUTS)
