# Backend Common Package Makefile
# Simple deployment commands

.PHONY: help clean build test version update-version publish

# Default target
help: ## Show available commands
	@echo "Backend Common Package - Available Commands:"
	@echo ""
	@echo "  clean         - Clean build artifacts"
	@echo "  build         - Build package"
	@echo "  test          - Run tests"
	@echo "  version       - Show current version"
	@echo "  update-version - Update version with multiple options:"
	@echo "                   make update-version VERSION=x.y.z        # Set specific version"
	@echo "                   make update-version AUTO=patch           # Auto-increment patch"
	@echo "                   make update-version AUTO=minor           # Auto-increment minor"
	@echo "                   make update-version AUTO=major           # Auto-increment major"
	@echo "                   make update-version CHECK=true           # Check versions"
	@echo "  publish       - Publish package (includes test + build + deploy)"
	@echo ""

# Clean build artifacts
clean: ## Clean build artifacts
	chmod +x scripts/clean.sh
	./scripts/clean.sh

# Build package
build: ## Build package
	chmod +x scripts/build.sh
	./scripts/build.sh

# Run tests
test: ## Run tests
	chmod +x scripts/test.sh
	./scripts/test.sh

# Show current version
version: ## Show current version
	chmod +x scripts/version.sh
	./scripts/version.sh

# Update version
update-version: ## Update version (usage: make update-version [VERSION=x.y.z] [AUTO=patch|minor|major] [CHECK=true])
	chmod +x scripts/update-version.sh
	@if [ "$(CHECK)" = "true" ]; then \
		./scripts/update-version.sh --check; \
	elif [ -n "$(AUTO)" ]; then \
		./scripts/update-version.sh --auto $(AUTO); \
	elif [ -n "$(VERSION)" ]; then \
		./scripts/update-version.sh $(VERSION); \
	else \
		echo "Usage:"; \
		echo "  make update-version VERSION=x.y.z        # Set specific version"; \
		echo "  make update-version AUTO=patch           # Auto-increment patch version"; \
		echo "  make update-version AUTO=minor           # Auto-increment minor version"; \
		echo "  make update-version AUTO=major           # Auto-increment major version"; \
		echo "  make update-version CHECK=true           # Check current versions"; \
		echo ""; \
		echo "Examples:"; \
		echo "  make update-version VERSION=0.0.4"; \
		echo "  make update-version AUTO=patch"; \
		echo "  make update-version CHECK=true"; \
		exit 1; \
	fi

# Publish package (full pipeline)
publish: ## Publish package (check version, test, build, deploy)
	chmod +x scripts/publish.sh
	./scripts/publish.sh
