IMAGE ?= python-learning:latest
ENGINE ?= podman
MOD ?=

RUN_CONTAINER = $(ENGINE) run --rm \
	-v "$(CURDIR):/workspace:Z" \
	-w /workspace \
	$(IMAGE)

.PHONY: help image check test test-all lint fmt fmt-check typecheck shell

help:
	@echo "Dostępne komendy:"
	@echo "  make image                              - Zbuduj obraz kontenera Python (jednorazowo)"
	@echo "  make check                              - Sprawdź lint (ruff) + typy (mypy)"
	@echo "  make test MOD=01-core/01-basics         - Uruchom testy wybranego rozdziału"
	@echo "  make test                               - Uruchom testy 01-core + 02-engineering-2026"
	@echo "  make test-all                           - Uruchom testy wszystkich 3 ścieżek"
	@echo "  make fmt                                - Sformatuj kod (ruff format)"
	@echo "  make fmt-check                          - Sprawdź formatowanie kodu"
	@echo "  make shell                              - Otwórz powłokę bash wewnątrz kontenera"

image:
	$(ENGINE) build -t $(IMAGE) -f Containerfile .

lint:
	$(RUN_CONTAINER) ruff check exercises

typecheck:
	$(RUN_CONTAINER) mypy exercises

check: lint typecheck

test:
ifdef MOD
	$(RUN_CONTAINER) pytest -v exercises/$(MOD)
else
	$(RUN_CONTAINER) pytest -v exercises/01-core exercises/02-engineering-2026
endif

test-all:
	$(RUN_CONTAINER) pytest -v exercises

fmt:
	$(RUN_CONTAINER) ruff format exercises

fmt-check:
	$(RUN_CONTAINER) ruff format --check exercises

shell:
	$(ENGINE) run --rm -it \
		-v "$(CURDIR):/workspace:Z" \
		-w /workspace \
		$(IMAGE) bash
