# Add any tasks that are not dependent on files to the .PHONY list.
.PHONY: clean dev env pip_dev lint test test_unit test_integration docker_test_integration_local docker_test_integration_local_down ci_unit_lint ci_test_integration

clean:
	rm -rf venv

dev:
	venv/bin/python dev.py

env:
	python3.13 -m venv venv

pip_dev: env
	venv/bin/pip install --upgrade pip
	venv/bin/pip install -r requirements.txt
	venv/bin/pip install -r requirements-dev.txt

lint: env
	venv/bin/ruff check product/ tests/

test_unit:
	venv/bin/py.test \
		--cov product tests/ \
		--cov-report xml \
		--junitxml=pyunit.xml \
		--ignore tests/integration

test_integration:
	venv/bin/py.test tests/integration --junitxml=pyunit.xml

up_dev:
	docker compose up \
		--build \
		--detach \
		--remove-orphans \
		product-dev

down_dev:
	docker compose down \
		product-dev

docker_unit_lint:
	docker compose up \
		--build \
		--exit-code-from unit-lint \
		--abort-on-container-exit \
		--remove-orphans \
		unit-lint

docker_test_integration:
	docker compose up \
		--build \
		--exit-code-from integration-test \
		--abort-on-container-exit \
		--remove-orphans \
		integration-test

# Run integration tests against the full local stack (DynamoDB Local +
# product-dev on host port 5001). One command: brings up deps, runs the
# integration-test container against the local app, tears down on exit.
docker_test_integration_local:
	docker compose -f docker-compose-dev.yml up \
		--build \
		--exit-code-from integration-test \
		--abort-on-container-exit \
		--remove-orphans \
		integration-test

docker_test_integration_local_down:
	docker compose -f docker-compose-dev.yml down --volumes --remove-orphans
