SHELL := /bin/bash
.DEFAULT_GOAL := help

VERSION := $(shell grep '^version:' pubspec.yaml | awk '{print $$2}')

# CONFIG=Debug (default for local dev) or Release — passed through to Swift SDK XCFramework build
CONFIG ?= Debug

.PHONY: help
help:
	@echo "Encore Flutter SDK"
	@echo ""
	@echo "Usage: make <target>"
	@echo ""
	@echo "Development:"
	@echo "  test                       Run Dart unit tests"
	@echo "  analyze                    Run Flutter analyzer"
	@echo ""
	@echo "Example App:"
	@echo "  setup-example              Install deps + pod install for example app"
	@echo "  demo-ios                   Build example app for iOS (open in Xcode to run)"
	@echo "  demo-android               Build example app for Android (open in Android Studio to run)"
	@echo "  demo-all                   Build for both iOS and Android"
	@echo "  clean-example              Remove build artifacts"
	@echo "  nuke                       Full clean: DerivedData + XCFramework + all build dirs"
	@echo ""
	@echo "Release:"
	@echo "  release                    Interactive release: bump version, validate, tag, and push"
	@echo "  dry-run                    Validate package for pub.dev"
	@echo ""
	@echo "Current version: $(VERSION)"

.PHONY: test
test:
	flutter test

.PHONY: analyze
analyze:
	flutter analyze --no-fatal-infos

.PHONY: setup-example
setup-example:
	@CONFIG=$(CONFIG) bash scripts/demo/setup-example.sh

.PHONY: demo-ios
demo-ios:
	@CONFIG=$(CONFIG) bash scripts/demo/demo-ios.sh

.PHONY: demo-android
demo-android:
	@bash scripts/demo/demo-android.sh

.PHONY: demo-all
demo-all: demo-ios demo-android  ## Build for both iOS and Android

.PHONY: clean-example
clean-example:
	@bash scripts/demo/clean-example.sh

.PHONY: nuke
nuke:
	@bash scripts/demo/clean-example.sh --nuke

.PHONY: dry-run
dry-run:
	flutter pub publish --dry-run

.PHONY: release
release:
	@bash scripts/release/publish-release.sh
