# ===
# Variables
# ===

PROJECT_NAME := ssocr-rs
CARGO        := cargo
BIN          := ssocr-rs

# Colors
COLOR_RESET   := \033[0m
COLOR_BOLD    := \033[1m
COLOR_GREEN   := \033[32m
COLOR_YELLOW  := \033[33m
COLOR_CYAN    := \033[36m

# ===
# Targets
# ===
.DEFAULT_GOAL := help
.PHONY: help build run check fmt lint fix test watch clean setup

build: ## Build release binary
	@echo "Building $(PROJECT_NAME) in release mode..."
	$(CARGO) build --release

run: ## Run ssocr-rs (usage: make run ARGS="-d 4 image.png")
	$(CARGO) run -- $(ARGS)

check: ## Fast compile check
	$(CARGO) check --workspace --all-targets

fmt: ## Format Rust code
	$(CARGO) fmt --all

lint: ## Run clippy linter and fail on warnings
	$(CARGO) clippy --workspace --all-targets -- -D warnings

fix: ## Automatically fix compiler warnings (where possible)
	$(CARGO) fix --workspace --all-targets --allow-no-vcs

test: ## Run all unit tests
	$(CARGO) test --workspace

watch: ## Run cargo watch for hot-reload development checking
	$(CARGO) watch -c -x check

setup: ## Install development tools (cargo-watch)
	@echo "Installing cargo-watch..."
	$(CARGO) install cargo-watch

clean: ## Remove build artifacts
	$(CARGO) clean

help: ## Show all commands
	@echo "Usage: make [target] [ARGS=\"...\"]"
	@echo ""
	@echo "Available targets:"
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(COLOR_CYAN)%-20s$(COLOR_RESET) %s\n", $$1, $$2}'