# --- Mobile App Development ---

.PHONY: mobile-install mobile-info mobile-client-dev-android mobile-staff-dev-android mobile-client-build mobile-staff-build

MOBILE_DIR := apps/mobile

# Device ID for running mobile apps (override with DEVICE=<id>)
# Find your device ID with: flutter devices
DEVICE ?= android

# --- General ---
mobile-install: install-melos
	@echo "--> Bootstrapping mobile workspace (Melos)..."
	@cd $(MOBILE_DIR) && melos bootstrap
	@echo "--> Generating localization files..."
	@cd $(MOBILE_DIR) && melos run gen:l10n

mobile-info:
	@echo "--> Fetching mobile command info..."
	@cd $(MOBILE_DIR) && melos run info

# --- Client App ---
mobile-client-dev-android:
	@echo "--> Running client app on Android (device: $(DEVICE))..."
	@cd $(MOBILE_DIR) && melos run start:client -- -d $(DEVICE)

mobile-client-build:
	@if [ -z "$(PLATFORM)" ]; then \
		echo "ERROR: PLATFORM is required (e.g. make mobile-client-build PLATFORM=apk)"; exit 1; \
	fi
	$(eval MODE ?= release)
	@echo "--> Building client app for $(PLATFORM) in $(MODE) mode..."
	@cd $(MOBILE_DIR) && \
		melos exec --scope="core_localization" -- "dart run slang" && \
		melos exec --scope="core_localization" -- "dart run build_runner build --delete-conflicting-outputs" && \
		melos exec --scope="krowwithus_client" -- "flutter build $(PLATFORM) --$(MODE)"

# --- Staff App ---
mobile-staff-dev-android:
	@echo "--> Running staff app on Android (device: $(DEVICE))..."
	@cd $(MOBILE_DIR) && melos run start:staff -- -d $(DEVICE)

mobile-staff-build:
	@if [ -z "$(PLATFORM)" ]; then \
		echo "ERROR: PLATFORM is required (e.g. make mobile-staff-build PLATFORM=apk)"; exit 1; \
	fi
	$(eval MODE ?= release)
	@echo "--> Building staff app for $(PLATFORM) in $(MODE) mode..."
	@cd $(MOBILE_DIR) && \
		melos exec --scope="core_localization" -- "dart run slang" && \
		melos exec --scope="core_localization" -- "dart run build_runner build --delete-conflicting-outputs" && \
		melos exec --scope="krowwithus_staff" -- "flutter build $(PLATFORM) --$(MODE)"
