# Dev Module — Development workflows for ontoref
# ================================================

# Format all code (Rust + TOML)
dev-fmt:
    @echo "Formatting code..."
    cargo fmt --all
    @command -v taplo >/dev/null && taplo format || true

# Build UnoCSS in watch mode (development)
dev-watch-css:
    cd assets/css && pnpm install && pnpm run watch

# Install pre-commit hooks + ontoref git hooks
dev-setup-hooks:
    #!/usr/bin/env bash
    set -euo pipefail
    echo "Installing pre-commit hooks..."
    if command -v pre-commit &> /dev/null; then
        pre-commit install && pre-commit install --hook-type pre-push
        echo "Pre-commit hooks installed"
    else
        echo "pre-commit not found. Install with: pip install pre-commit"
        exit 1
    fi
    git_hooks_dir="$(git rev-parse --git-dir)/hooks"
    hook_body='#!/usr/bin/env bash'$'\n''nu "$(git rev-parse --show-toplevel)/reflection/hooks/git-event.nu" "$1" 2>/dev/null || true'
    for hook in post-merge post-checkout; do
        printf '%s\n' "${hook_body}" > "${git_hooks_dir}/${hook}"
        chmod +x "${git_hooks_dir}/${hook}"
        echo "${hook} hook installed"
    done

# Run pre-commit on all files
dev-hooks-run-all:
    @echo "Running pre-commit on all files..."
    pre-commit run --all-files

# Clean build artifacts
dev-clean:
    @echo "Cleaning..."
    cargo clean
    rm -rf target/
    rm -f sbom.json lcov.info

# Run ontoref sync audit (quick health check)
dev-audit:
    ONTOREF_ACTOR=developer ./ontoref sync audit

# Generate documentation
dev-docs:
    @echo "Generating documentation..."
    cargo doc --no-deps --open
