-include .env
export

deps:
ifeq ($(MODE), ci)
	uv sync --all-extras --locked --no-cache
else
	uv sync --all-extras
endif

lock:
	uv lock --upgrade

lint:
ifeq ($(MODE), ci)
	uv run ruff check flowra/ tests/ examples/
	uv run ruff format --check flowra/ tests/ examples/
else
	uv run ruff check --fix flowra/ tests/ examples/
	uv run ruff format flowra/ tests/ examples/
endif
	uv run pyright

# ── test parameters ──────────────────────────────────────────────────
# Examples:
#   make test                          # all tests, parallel
#   make test name="some_name"         # filter by name (-k)
#   make test parallel=0               # sequential
#   make test parallel=4               # 4 workers
#   make test name="e2e" parallel=0    # filter + sequential
_TEST_ARGS = $(if $(parallel),$(if $(filter 0,$(parallel)),,-n $(parallel)),-n auto) \
             $(if $(name),-k $(name))

test:
	uv run pytest tests/ $(_TEST_ARGS) $(args)

test-unit:
	uv run pytest tests/ --ignore=tests/llm/providers $(_TEST_ARGS) $(args)

test-e2e:
	uv run pytest tests/llm/providers/ -k e2e $(_TEST_ARGS) $(args)

check: lint test

example1:
	uv run python examples/menu_agent.py $(args)

example2:
	uv run python examples/menu_agent_class.py $(args)

chat:
	CRASH_CHANCE=$(or $(crash),0) TOOL_DELAY=$(or $(delay),0) uv run python examples/console_chat.py $(if $(model),--model $(model)) $(if $(resume),--resume $(resume)) $(if $(input),--input "$(input)") $(args)
# make chat                        — new session
# make chat resume=last            — resume last session
# make chat resume=<session_id>    — resume specific session
# make chat input="What is 2+2?"   — batch mode (single message)
# make chat crash=0.5 input="..."  — crash recovery demo
# make chat delay=3                — slow tools (seconds)

chat-tui:
	CRASH_CHANCE=$(or $(crash),0) TOOL_DELAY=$(or $(delay),0) uv run python examples/tui_chat.py $(if $(model),--model $(model)) $(if $(resume),--resume $(resume)) $(args)
