#==================================================================================== #
# HELPERS
#==================================================================================== #

## help: print this help message
.PHONY: help
help:
	@echo 'Usage:'
	@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' |  sed -e 's/^/ /'

.PHONY: confirm
confirm:
	@echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]

#==================================================================================== #
# BUF Commands
#==================================================================================== #

## lint: run the buf lint command
.PHONY: lint
lint:
	buf lint

## format: run the buf format command
.PHONY: format
format:
	buf format -d -w

## breaking: run the buf breaking command
.PHONY: breaking
breaking:
	buf breaking --against ".git#branch=main"

## generate: run the buf generate command
.PHONY: generate
generate:
	@echo 'Deleting old files...'
	rm -rf ./messages/*
	rm -r ./src/cobotar_protocol/*
	touch ./src/cobotar_protocol/__init__.py
	rm -rf ./csharp/*.cs
	rm -rf ./lib/*
	@echo 'Generating new files...'
	buf generate
	go run ./cmd/subjectgen generate

## subject-check: validate the subject catalog and ensure generated helpers are current
.PHONY: subject-check
subject-check:
	go test ./internal/subjectgen ./subjects
	go run ./cmd/subjectgen check

## verify: format, lint, generate protobuf and subject files, and verify subjects
## TODO: removed breaking until a more stable protocol have been established
.PHONY: verify
verify: format lint generate subject-check
	@echo 'Remember to check if new files were created!'

## publish bump=$1: run checks, bump version, and publish. bump={major,minor,patch}
.PHONY: publish
publish: verify
	@echo 'Verification complete'
	bump-my-version bump ${bump} --no-allow-dirty
	git push
	git push --tags
	@echo 'New version is published'
