.PHONY: pre-commit
pre-commit: version analyze format build

.PHONY: analyze
analyze: version
	flutter analyze

.PHONY: format
format:
	dart format lib

.PHONY: version
version:
	@echo "Checking for git repository..."
	@if git rev-parse --git-dir > /dev/null 2>&1; then \
		echo "Generating version from git tags..."; \
		VERSION=$$(git describe --tags --always --dirty 2>/dev/null || echo "v0.0.0-unknown"); \
		echo "// This file is auto-generated. Do not edit manually." > lib/version.dart; \
		echo "// Generated by: make version" >> lib/version.dart; \
		echo "const String appVersion = '$$VERSION';" >> lib/version.dart; \
		echo "Generated version: $$VERSION"; \
	else \
		echo "Not in a git repository - preserving existing version.dart"; \
		if [ ! -f lib/version.dart ]; then \
			echo "No version.dart found, creating with default version..."; \
			echo "// This file is auto-generated. Do not edit manually." > lib/version.dart; \
			echo "// Generated by: make version" >> lib/version.dart; \
			echo "const String appVersion = 'v0.0.0-unknown';" >> lib/version.dart; \
		else \
			echo "Using existing version.dart"; \
		fi; \
	fi

.PHONY: build
build: version
	flutter build web --wasm
