#!/usr/bin/env just --justfile

[group('help')]
[private]
default:
    @ just --list --list-heading $'justfile manual page:\n'

# show help
[group('help')]
help: default

# runs service
[group('run')]
run:
    @ uv run python manage.py runserver

style:
    just format
    just lint
    just mypy

check:
    just style
    just test
    just test-coverage

# lints codebase using golangci-lint
[group('lint')]
lint:
    @ uv run ruff check .

# lints and fixes codebase using ruff
[group('lint')]
fix:
    @ uv run ruff check . --fix

# formats codebase using ruff
[group('lint')]
format:
    @ uv run ruff format .

alias fmt := format

# lints codebase using mypy
[group('lint')]
mypy:
    @ uv run mypy .

# run tests
[group('test')]
test:
    @ uv run python manage.py test

# run integration tests
[group('test')]
test-integration:
    @ uv run python manage.py test tests.integration

# run tests with coverage report
[group('test')]
test-coverage:
    @ uv run coverage run --source="." manage.py test

# show coverage report
[group('test')]
show-coverage:
    @ uv run coverage report

# run tests, produce junit report
[group('ci')]
ci-test:
    @ mkdir -p reports .cov
    @ uv run coverage run --source="." manage.py test \
        --testrunner=xmlrunner.extra.djangotestrunner.XMLTestRunner \
        --settings="config.settings.ci"
    @ uv run coverage report | tee .cov/coverage.txt
    @ uv run coverage xml -o .cov/coverage.xml

# generates migrations
[group('generate')]
make-migrations:
    @ uv run python manage.py makemigrations

# applies migrations
[group('generate')]
apply-migrations:
    @ uv run python manage.py migrate

alias m := apply-migrations
