PY ?= python3
VENV ?= .venv
BIN := $(VENV)/bin
IMAGE ?= awg-dash:dev
COMPOSE_DEV := deploy/docker-compose.dev.yml

.PHONY: help venv lint fmt test build dev-up dev-down dev-logs test-netns

help:
	@grep -E '^[a-zA-Z_-]+:' $(MAKEFILE_LIST) | sed 's/:.*//' | sort -u

venv:
	$(PY) -m venv $(VENV)
	$(BIN)/pip install -U pip
	$(BIN)/pip install -r requirements-dev.txt

lint:
	$(BIN)/ruff check backend
	$(BIN)/mypy backend

fmt:
	$(BIN)/ruff format backend
	$(BIN)/ruff check --fix backend

test:
	$(BIN)/pytest

build:
	@test -f deploy/Dockerfile || { echo 'deploy/Dockerfile ещё нет — задача #18'; exit 1; }
	docker build -f deploy/Dockerfile -t $(IMAGE) .

dev-up:
	@test -f $(COMPOSE_DEV) || { echo '$(COMPOSE_DEV) ещё нет — задача #21'; exit 1; }
	docker compose -f $(COMPOSE_DEV) up -d --build

dev-down:
	docker compose -f $(COMPOSE_DEV) down

dev-logs:
	docker compose -f $(COMPOSE_DEV) logs -f --tail=100

test-netns:
	@test -d tests/netns || { echo 'tests/netns ещё нет — задача #21'; exit 1; }
	bash tests/netns/run.sh
