# Justfile for .
# Task runner for Django development
# Install just: https://github.com/casey/just

# Default task: show available commands
default:
    @just --list

# Run development server
dev:
    uv run python manage.py runserver

# Run development server with custom host and port
dev-server HOST="0.0.0.0" PORT="8000":
    uv run python manage.py runserver {{HOST}}:{{PORT}}

# Create migrations for all apps
makemigrations:
    uv run python manage.py makemigrations

# Create migrations for specific app
makemigrations-app APP:
    uv run python manage.py makemigrations {{APP}}

# Run all migrations
migrate:
    uv run python manage.py migrate

# Reset database (delete all migrations)
reset-db:
    uv run python manage.py flush --noinput
    uv run python manage.py migrate

# Create superuser
createsuperuser:
    uv run python manage.py createsuperuser

# Collect static files
collectstatic:
    uv run python manage.py collectstatic --noinput

# Run Django shell
shell:
    uv run python manage.py shell

# Run Django shell plus (IPython)
shell-plus:
    uv run python manage.py shell_plus

# Run tests
test:
    uv run python manage.py test

# Run tests with coverage
test-coverage:
    uv run pytest --cov=. --cov-report=html --cov-report=term

# Lint code with ruff
lint:
    uv run ruff check .

# Format code with ruff
format:
    uv run ruff format .

# Lint and format code
style:
    uv run ruff check .
    uv run ruff format .

# Check security issues
check:
    uv run python manage.py check

# Check security issues (production settings)
check-deploy:
    uv run python manage.py check --deploy

# Show all database migrations status
showmigrations:
    uv run python manage.py showmigrations

# Sync dependencies (uv equivalent of pip freeze)
requirements:
    uv pip compile

# Run all linting and checks
ci:
    uv run ruff check .
    uv run ruff format --check .
    uv run python manage.py check

# Start interactive shell
shell-ipython:
    uv run python manage.py shell_plus

# Clear all cache
clear-cache:
    uv run python manage.py clear_cache

# Show Django version
version:
    uv run python manage.py version

# Run database shell
dbshell:
    uv run python manage.py dbshell

# Start production server with gunicorn
server:
    uv run gunicorn ..wsgi:application --bind 0.0.0.0:8000

# Start production server with gunicorn workers
server-prod WORKERS="4":
    uv run gunicorn ..wsgi:application --bind 0.0.0.0:8000 --workers {{WORKERS}}

# Start production server with gunicorn and reload on file changes
server-watch:
    uv run gunicorn ..wsgi:application --bind 0.0.0.0:8000 --reload

# Clean Python cache files
clean:
    find . -type d -name "__pycache__" -exec rm -rf {} +
    find . -type f -name "*.pyc" -delete
    find . -type f -name "*.pyo" -delete
    find . -type f -name ".coverage" -delete
    find . -type d -name "*.egg-info" -exec rm -rf {} +
    rm -rf htmlcov/
    rm -rf .pytest_cache/

# Setup project for development (using uv)
setup:
    uv sync
    uv run python manage.py migrate
    uv run python manage.py createsuperuser

# Complete setup including static files
setup-complete:
    uv sync
    uv run python manage.py migrate
    uv run python manage.py collectstatic --noinput
    uv run python manage.py createsuperuser

# Install a new package
install PACKAGE:
    uv add {{PACKAGE}}

# Install a dev package
install-dev PACKAGE:
    uv add --dev {{PACKAGE}}

# Remove a package
remove PACKAGE:
    uv remove {{PACKAGE}}
