PROTOC := C:/Users/SSAFY/AppData/Local/Microsoft/WinGet/Packages/Google.Protobuf_Microsoft.Winget.Source_8wekyb3d8bbwe/bin/protoc.exe
GOPATH_BIN := $(shell go env GOPATH)/bin

.PHONY: build run proto proto-unity proto-all clean test testclient

# Build the server binary.
build:
	go build -o bin/server.exe ./cmd/server

# Run the server.
run:
	go run ./cmd/server -config config/config.yaml

# Generate Go server code from protobuf.
proto:
	PATH="$(GOPATH_BIN):$(PATH)" $(PROTOC) \
		--go_out=proto/gen/pb \
		--go_opt=paths=source_relative \
		--proto_path=proto \
		proto/messages.proto

# Generate C# Unity client code from protobuf.
proto-unity:
	$(PROTOC) \
		--csharp_out=./unity/Assets/Scripts/Proto \
		--proto_path=./proto \
		proto/messages.proto

# Generate both Go and C# at once.
proto-all: proto proto-unity

# Clean build artifacts.
clean:
	rm -rf bin/

# Run tests.
test:
	go test ./... -v -race

# Run with AOI disabled for comparison.
run-no-aoi:
	AOI_ENABLED=false go run ./cmd/server -config config/config.yaml

# Run the WebSocket test client (server must be running).
testclient:
	go run ./cmd/testclient

# Run test client with specific scenario (auth|move|combat|metrics|all).
testclient-auth:
	go run ./cmd/testclient -scenario auth

testclient-combat:
	go run ./cmd/testclient -scenario combat

testclient-metrics:
	go run ./cmd/testclient -scenario metrics

# Load test: 10 clients for 15 seconds.
loadtest:
	go run ./cmd/testclient -clients 10 -duration 15s
