.PHONY: build run test clean docker-build docker-run help

BINARY_NAME=middleware
DOCKER_IMAGE=slack-to-ntfy
VERSION?=latest

# DOCKER_REGISTRY is optional. If set, it will be used for pushing. Otherwise, images are loaded locally.

# Default target
help:
	@echo "Available targets:"
	@echo "  build        - Build the Go binary"
	@echo "  run          - Run the application locally"
	@echo "  test         - Run tests"
	@echo "  clean        - Clean build artifacts"
	@echo "  docker-build - Build Docker image"
	@echo "  docker-run   - Run with Docker Compose"
	@echo "  docker-stop  - Stop Docker Compose"
	@echo "  logs         - Show Docker logs"

build:
	go build -o $(BINARY_NAME) main.go

run: build
	./$(BINARY_NAME)

test:
	go test -v ./...

clean:
	go clean
	rm -f $(BINARY_NAME)

docker-build:
ifndef DOCKER_REGISTRY
	# DOCKER_REGISTRY is not set, load locally
	docker buildx build --platform linux/amd64,linux/arm64 -t $(DOCKER_IMAGE):$(VERSION) --load .
else
	# DOCKER_REGISTRY is set, push to registry
	docker buildx build --platform linux/amd64,linux/arm64 -t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE):$(VERSION) --push .
endif

docker-run:
	docker compose up -d

docker-stop:
	docker compose down

logs:
	docker compose logs -f

# Development helpers
fmt:
	go fmt ./...

vet:
	go vet ./...

mod-tidy:
	go mod tidy

deps: mod-tidy
	go mod download
