# Rustelo Build Cache Management (PAP-compliant)
# Unified build cache operations using Nushell-based management

# =============================================================================
# UNIFIED CACHE COMMAND
# =============================================================================

# Universal build cache command - handles all build cache operations
cache *args:
    #!/usr/bin/env bash
    cd {{justfile_directory()}}

    # Parse arguments
    if [ $# -eq 0 ]; then
        # Show build cache status by default
        nu ./scripts/cache-manager.nu cache status
        echo ""
        echo "💡 Usage: just cache <command> [args...]"
        echo "   Commands: status, list, stats, clean, force, path"
        echo "   Examples:"
        echo "     just cache status           # Show build cache overview"
        echo "     just cache clean css        # Clean CSS build cache"
        echo "     just cache clean docs       # Clean generated documentation"
        echo "     just cache force routes     # Force regenerate route cache"
        echo "     just cache force docs       # Force regenerate documentation"
        echo "     just cache path client      # Get client cache path"
        echo "     just cache path docs        # Get documentation cache path"
        echo ""
        echo "ℹ️  Note: Manages build-time caching, not server runtime cache."
        exit 0
    fi

    # Execute the cache command
    nu ./scripts/cache-manager.nu cache "$@"

# =============================================================================
# ESSENTIAL SHORTCUTS (minimal set)
# =============================================================================

# Quick build cache status
cs:
    @just cache::cache status

# Show cache status (alias for cs)
status:
    #!/usr/bin/env bash
    cd {{justfile_directory()}}
    nu ./scripts/cache-manager.nu cache status

# Show cache statistics
stats:
    #!/usr/bin/env bash
    cd {{justfile_directory()}}
    nu ./scripts/cache-manager.nu cache stats

# List cache files
list:
    #!/usr/bin/env bash
    cd {{justfile_directory()}}
    nu ./scripts/cache-manager.nu cache list

# Clean specific cache type
clean cache_type:
    #!/usr/bin/env bash
    cd {{justfile_directory()}}
    nu ./scripts/cache-manager.nu cache clean {{cache_type}}

# Force rebuild specific cache type
force cache_type:
    #!/usr/bin/env bash
    cd {{justfile_directory()}}
    nu ./scripts/cache-manager.nu cache force {{cache_type}}

# Get cache path
path cache_type="build":
    #!/usr/bin/env bash
    cd {{justfile_directory()}}
    nu ./scripts/cache-manager.nu cache path {{cache_type}}

# Clean all build caches (common operation)
cache-clean:
    @just cache::cache clean all

# Force rebuild all build caches
cache-rebuild:
    @just cache::cache clean all
    @cargo leptos build

# =============================================================================
# HELP SYSTEM INTEGRATION
# =============================================================================

# Cache help menu (integrated with just h system)
cache-help:
    @echo "🗄️  Rustelo Build Cache Management (PAP-compliant)"
    @echo "=================================================="
    @echo ""
    @echo "🔍 Build Cache Operations:"
    @echo "  just cache status              # Show build cache overview"
    @echo "  just cache list                # List all cached build files"
    @echo "  just cache stats               # Detailed build cache statistics"
    @echo ""
    @echo "🧹 Build Cache Cleaning:"
    @echo "  just cache clean <type>        # Clean specific build cache"
    @echo "    Types: css, routes, pages, docs, js, client, server, rustelo, all"
    @echo ""
    @echo "🔄 Force Build Operations:"
    @echo "  just cache force <type>        # Force regenerate build artifacts"
    @echo "    Types: css, routes, pages, docs"
    @echo ""
    @echo "📍 Build Cache Paths:"
    @echo "  just cache path <type>         # Get build cache path"
    @echo "    Types: client, server, docs, build, deployment"
    @echo ""
    @echo "⚡ Quick Shortcuts:"
    @echo "  just cs                        # Build cache status"
    @echo "  just cache-clean               # Clean all build caches"
    @echo "  just cache-rebuild             # Clean + rebuild all artifacts"
    @echo ""
    @echo "Examples:"
    @echo "  just cache clean css           # Clean CSS build cache only"
    @echo "  just cache clean docs          # Clean generated documentation"
    @echo "  just cache force routes        # Force regenerate route cache"
    @echo "  just cache force docs          # Force regenerate documentation"
    @echo "  just cache stats               # Detailed build cache statistics"
    @echo ""
    @echo "ℹ️  Note: This manages build-time caching (CSS, routes, pages, docs)."
    @echo "    For server runtime caching, see server configuration."
