.DEFAULT_GOAL := check

ESP_PORT ?= /dev/ttyACM0

# Run the full local check suite — same order as CI would.
check: fmt-check clippy test
	@echo "✅ All checks passed"

# Apply rustfmt to all files.
fmt:
	cargo fmt

# Check formatting without modifying files (CI-safe).
fmt-check:
	cargo fmt --check

# Run Clippy and treat warnings as errors.
clippy:
	cargo clippy -- -D warnings

# Run the test suite.
test:
	cargo test

# Apply fmt + clippy auto-fixes in one shot.
fix:
	cargo fmt
	cargo clippy --fix --allow-dirty --allow-staged

# Start the K-Frame server.
server:
	cargo run --bin bootstrap

# Start the desktop client.
desktop:
	cargo run --bin client-desktop

# Build ESP32 firmware.
esp-build:
	cd crates/client-esp32 && cargo build --release

# Flash ESP32 firmware.
esp-flash:
	cd crates/client-esp32 && cargo espflash flash --port $(ESP_PORT) --release

# Flash and monitor ESP32.
esp-run:
	cd crates/client-esp32 && cargo espflash flash --port $(ESP_PORT) --release --monitor

# Monitor ESP32 serial output.
esp-monitor:
	cd crates/client-esp32 && cargo espflash monitor --port $(ESP_PORT)

# Erase ESP32 flash (recovery).
esp-erase:
	esptool --port $(ESP_PORT) erase-flash

.PHONY: check fmt fmt-check clippy test fix server desktop esp-build esp-flash esp-run esp-monitor esp-erase
