# ╔══════════════════════════════════════════════════════════════════════╗
# ║                      DEVELOPMENT UTILITIES                           ║
# ║                   Watch, format, lint, docs                          ║
# ╚══════════════════════════════════════════════════════════════════════╝

# Help for dev module
help:
    @echo "DEVELOPMENT MODULE"
    @echo ""
    @echo "Code quality:"
    @echo "  just dev::fmt           Format code (Rust + TOML + Nickel)"
    @echo "  just dev::fmt-check     Check format (no changes)"
    @echo "  just dev::lint          Run clippy linter"
    @echo "  just dev::lint-all      Lint Rust + Nickel + NuShell"
    @echo "  just dev::audit         Audit dependencies"
    @echo ""
    @echo "Documentation:"
    @echo "  just dev::docs          Generate and open docs"
    @echo "  just dev::docs-gen      Generate docs only"
    @echo ""
    @echo "Common tasks:"
    @echo "  just dev::build         Build default features"
    @echo "  just dev::watch         Watch and rebuild on changes"
    @echo "  just dev::check         Check + fmt + lint"
    @echo ""
    @echo "Inspect:"
    @echo "  just dev::info          Show workspace info"
    @echo "  just dev::tree          Show dependency tree"

# === CODE FORMATTING ===

# Format all code (Rust + TOML + Nickel)
[doc("Format Rust, TOML, and Nickel code")]
fmt:
    @echo "=== Formatting code ==="
    cargo fmt --all
    @echo "✓ Rust code formatted"

# Check code formatting without modifying
[doc("Check code format (no changes)")]
fmt-check:
    @echo "=== Checking code format ==="
    cargo fmt --all -- --check
    @echo "✓ Code format check passed"

# === LINTING ===

# Run clippy linter on Rust code
[doc("Run clippy linter")]
lint:
    @echo "=== Running clippy ==="
    cargo clippy --workspace --all-features -- -D warnings
    @echo "✓ Clippy check passed"

# Lint all languages (Rust + Nickel + NuShell)
[doc("Lint Rust, Nickel, and NuShell code")]
lint-all:
    @echo "=== Linting all code ==="
    @just dev::lint
    @just nickel::lint
    @echo "✓ All linting passed"

# Audit dependencies for security vulnerabilities
[doc("Audit dependencies")]
audit:
    @echo "=== Auditing dependencies ==="
    cargo audit
    @echo "✓ Dependency audit passed"

# === DOCUMENTATION ===

# Generate and open documentation
[doc("Generate and open Rust docs")]
docs:
    @echo "=== Generating documentation ==="
    cargo doc --workspace --all-features --no-deps --open

# Generate documentation only (no open)
[doc("Generate Rust docs only")]
docs-gen:
    @echo "=== Generating documentation ==="
    cargo doc --workspace --all-features --no-deps

# === COMMON TASKS ===

# Build default features
[doc("Build workspace with default features")]
build:
    @cargo build --workspace

# Watch and rebuild on changes
[doc("Watch for changes and rebuild")]
watch:
    @echo "=== Watching for changes ==="
    cargo watch -x "build --workspace"

# Check + format + lint
[doc("Run check + fmt + lint")]
check:
    @just dev::fmt-check
    @just dev::lint
    @cargo check --workspace --all-features
    @echo "✓ All checks passed"

# === INSPECT ===

# Show workspace information
[doc("Show workspace information")]
info:
    @echo "=== Workspace Information ==="
    @cargo tree --workspace --depth 1
    @echo ""
    @echo "=== Crates ==="
    @ls -1 crates/
    @echo ""
    @echo "=== Features (kogral-core) ==="
    @cargo tree --package kogral-core --features full --depth 0

# Show dependency tree
[doc("Show complete dependency tree")]
tree:
    @echo "=== Dependency Tree ==="
    cargo tree --workspace
