# Full Distribution Module - Complete Nushell Distribution
# Commands for building, collecting, and packaging complete Nushell distributions

# 🚀 NUSHELL BUILD COMMANDS

# Build nushell with all workspace plugins
[no-cd]
build-nushell:
    @echo "🔨 Building Nushell with all workspace plugins..."
    @{{justfile_directory()}}/scripts/run.sh build_nushell.nu --release

# Build nushell in debug mode
[no-cd]
build-nushell-debug:
    @echo "🔨 Building Nushell (debug mode)..."
    @{{justfile_directory()}}/scripts/run.sh build_nushell.nu

# Build nushell for specific target
[no-cd]
build-nushell-target TARGET:
    @echo "🔨 Building Nushell for {{TARGET}}..."
    @{{justfile_directory()}}/scripts/run.sh build_nushell.nu --release --target {{TARGET}}

# Build nushell with custom features
[no-cd]
build-nushell-features FEATURES:
    @echo "🔨 Building Nushell with features: {{FEATURES}}..."
    @{{justfile_directory()}}/scripts/run.sh build_nushell.nu --release --features {{FEATURES}}

# Build nushell with custom profile
[no-cd]
build-nushell-profile PROFILE:
    @echo "🔨 Building Nushell with profile: {{PROFILE}}..."
    @{{justfile_directory()}}/scripts/run.sh build_nushell.nu --profile {{PROFILE}}

# Check nushell build dependencies
[no-cd]
build-nushell-deps:
    @echo "🔍 Checking Nushell build dependencies..."
    @{{justfile_directory()}}/scripts/run.sh build_nushell.nu deps

# Show nushell build information
[no-cd]
build-nushell-info:
    @echo "ℹ️  Nushell build information..."
    @{{justfile_directory()}}/scripts/run.sh build_nushell.nu info

# 📦 FULL BUILD WORKFLOWS

# Build everything: nushell + all plugins
[no-cd]
build-full:
    @echo "🚀 Building complete distribution (nushell + all plugins)..."
    @just validate-nushell
    @just build-nushell
    @just build

# Build full release (optimized)
[no-cd]
build-full-release:
    @echo "🚀 Building full release distribution..."
    @just validate-nushell
    @just build-nushell
    @just build-release

# Build full distribution for specific target
[no-cd]
build-full-target TARGET:
    @echo "🚀 Building full distribution for {{TARGET}}..."
    @just validate-nushell
    @just build-nushell-target {{TARGET}}
    @just build-cross {{TARGET}}

# Build full distribution for all targets
[no-cd]
build-full-cross:
    @echo "🌍 Building full distribution for all targets..."
    @just validate-nushell
    @just build-nushell
    @just build-cross-all

# 📋 FULL COLLECTION COMMANDS

# Collect all binaries (nushell + plugins)
[no-cd]
collect-full:
    @echo "📦 Collecting full binaries (nushell + plugins)..."
    @{{justfile_directory()}}/scripts/run.sh collect_full_binaries.nu --release --force

# Collect full binaries in debug mode
[no-cd]
collect-full-debug:
    @echo "📦 Collecting full binaries (debug mode)..."
    @{{justfile_directory()}}/scripts/run.sh collect_full_binaries.nu --force

# List available full binaries
[no-cd]
collect-full-list:
    @echo "📋 Available full binaries:"
    @{{justfile_directory()}}/scripts/run.sh collect_full_binaries.nu --list

# List available platforms for full collection
[no-cd]
collect-full-platforms:
    @echo "🌍 Available platforms for full collection:"
    @{{justfile_directory()}}/scripts/run.sh collect_full_binaries.nu --list-platforms

# Collect full binaries for specific platform
[no-cd]
collect-full-platform PLATFORM:
    @echo "📦 Collecting full binaries for {{PLATFORM}}..."
    @{{justfile_directory()}}/scripts/run.sh collect_full_binaries.nu --platform {{PLATFORM}} --release --force

# Collect full binaries for all platforms
[no-cd]
collect-full-all:
    @echo "🌍 Collecting full binaries for all platforms..."
    @{{justfile_directory()}}/scripts/run.sh collect_full_binaries.nu --all-platforms --release --force

# Collect only plugins (exclude nushell)
[no-cd]
collect-plugins-only:
    @echo "📦 Collecting plugins only..."
    @{{justfile_directory()}}/scripts/run.sh collect_full_binaries.nu --release --force --include-nushell=false

# Collect full binaries with custom profile
[no-cd]
collect-full-profile PROFILE:
    @echo "📦 Collecting full binaries with profile {{PROFILE}}..."
    @{{justfile_directory()}}/scripts/run.sh collect_full_binaries.nu --profile {{PROFILE}} --force

# 📦 FULL PACKAGING COMMANDS

# Create full distribution package
[no-cd]
pack-full:
    @echo "📦 Creating full distribution package..."
    @{{justfile_directory()}}/scripts/run.sh create_distribution_packages.nu --force

# Package full distribution for specific platform
[no-cd]
pack-full-platform PLATFORM:
    @echo "📦 Packaging full distribution for {{PLATFORM}}..."
    @{{justfile_directory()}}/scripts/run.sh create_distribution_packages.nu --platform {{PLATFORM}} --force

# Package full distribution for all platforms
[no-cd]
pack-full-all:
    @echo "🌍 Packaging full distribution for all platforms..."
    @{{justfile_directory()}}/scripts/run.sh create_distribution_packages.nu --all-platforms --force

# Package full distribution with checksums
[no-cd]
pack-full-checksums:
    @echo "🔐 Packaging full distribution with checksums..."
    @{{justfile_directory()}}/scripts/run.sh create_distribution_packages.nu --all-platforms --checksums --force

# Package full distribution with bootstrap installers
[no-cd]
pack-full-bootstrap:
    @echo "🚀 Packaging full distribution with bootstrap installers..."
    @{{justfile_directory()}}/scripts/run.sh create_distribution_packages.nu --all-platforms --checksums --bootstrap --force

# Show what would be packaged
[no-cd]
pack-full-list:
    @echo "📋 Files that would be packaged in full distribution:"
    @{{justfile_directory()}}/scripts/run.sh create_distribution_packages.nu --list

# 🔐 UNIFIED CHECKSUMS (for both nushell-full and plugins-only)

# Generate unified checksums for ALL distributions (nushell-full + plugins-only)
[no-cd]
pack-unified-checksums:
    @echo "🔐 Generating unified checksums for all distributions..."
    @{{justfile_directory()}}/scripts/run.sh generate_unified_checksums.nu --force

# Generate checksums with custom output directory
[no-cd]
pack-unified-checksums-output OUTPUT:
    @echo "🔐 Generating unified checksums in {{OUTPUT}}..."
    @{{justfile_directory()}}/scripts/run.sh generate_unified_checksums.nu --output {{OUTPUT}} --force

# 🚀 FULL RELEASE WORKFLOWS

# Complete full release workflow
[no-cd]
release-full:
    @echo "🚀 Running complete full release workflow..."
    @just validate-nushell
    @just build-full-release
    @just collect-full
    @just pack-full-checksums

# Cross-platform full release
[no-cd]
release-full-cross:
    @echo "🌍 Running cross-platform full release workflow..."
    @just validate-nushell
    @just build-full-cross
    @just collect-full-all
    @just pack-full-bootstrap

# Quick full release for current platform
[no-cd]
release-full-quick:
    @echo "⚡ Quick full release for current platform..."
    @just validate-nushell
    @just build-full-release
    @just collect-full
    @just pack-full

# Full release for specific target
[no-cd]
release-full-target TARGET:
    @echo "🎯 Full release for {{TARGET}}..."
    @just validate-nushell
    @just build-full-target {{TARGET}}
    @just collect-full-platform {{TARGET}}
    @just pack-full-platform {{TARGET}}

# Development full release (debug mode)
[no-cd]
release-full-dev:
    @echo "🛠️  Development full release..."
    @just validate-nushell
    @just build-full
    @just collect-full-debug
    @just pack-full

# 🎯 UNIFIED RELEASE WORKFLOW (both nushell-full + plugins-only distributions)

# Complete unified release: builds both distribution types with unified checksums
[no-cd]
release-full-unified:
    @echo "🚀 Complete unified release workflow (nushell-full + plugins-only)..."
    @just validate-nushell
    @just build-full-release
    @just collect-full-all
    @echo "📦 Creating nushell-full packages..."
    @just pack-full-all
    @echo "📦 Creating plugins-only packages..."
    @just pack-all
    @echo "🔐 Generating unified checksums for both distributions..."
    @just pack-unified-checksums
    @echo "✅ Unified release complete!"

# Cross-platform unified release with bootstrap installers
[no-cd]
release-full-unified-bootstrap:
    @echo "🚀 Cross-platform unified release with bootstrap installers..."
    @just validate-nushell
    @just build-full-cross
    @just collect-full-all
    @echo "📦 Creating nushell-full packages with bootstrap..."
    @just pack-full-bootstrap
    @echo "📦 Creating plugins-only packages..."
    @just pack-all
    @echo "🔐 Generating unified checksums for both distributions..."
    @just pack-unified-checksums
    @echo "✅ Unified bootstrap release complete!"

# 🔍 VERIFICATION COMMANDS

# Verify full installation
[no-cd]
verify-full:
    @echo "🔍 Verifying full installation..."
    @{{justfile_directory()}}/scripts/run.sh verify_installation.nu

# Test full installation locally
[no-cd]
test-install-full:
    @echo "🧪 Testing full installation locally..."
    @{{justfile_directory()}}/scripts/run.sh install_full_nushell.nu --test --verify

# Verify specific platform installation
[no-cd]
verify-full-platform PLATFORM:
    @echo "🔍 Verifying {{PLATFORM}} installation..."
    @{{justfile_directory()}}/scripts/run.sh verify_installation.nu --platform {{PLATFORM}}

# 📊 FULL DISTRIBUTION INFORMATION

# Show full distribution status
[no-cd]
full-status:
    @echo "📊 Full Distribution Status"
    @echo "=========================="
    @echo ""
    @echo "🔨 Build Status:"
    @if [ -f "nushell/target/release/nu" ] || [ -f "nushell/target/release/nu.exe" ]; then \
        echo "  ✅ Nushell binary built"; \
    else \
        echo "  ❌ Nushell binary not built"; \
    fi
    @echo ""
    @echo "📦 Collection Status:"
    @if [ -d "distribution" ]; then \
        echo "  ✅ Distribution directory exists"; \
        echo "  📁 Platforms: $$(find distribution -maxdepth 1 -type d ! -name distribution | wc -l)"; \
    else \
        echo "  ❌ Distribution directory not found"; \
    fi
    @echo ""
    @echo "📦 Packaging Status:"
    @if [ -d "bin_archives" ]; then \
        echo "  ✅ Package archives exist"; \
        echo "  📦 Archives: $$(ls bin_archives/*.tar.gz bin_archives/*.zip 2>/dev/null | wc -l)"; \
    else \
        echo "  ❌ No package archives found"; \
    fi

# Show full distribution help
[no-cd]
full-help:
    @echo "🚀 Full Distribution Module Help"
    @echo "==============================="
    @echo ""
    @echo "NUSHELL + SYSTEM PLUGINS BUILD:"
    @echo "  build-nushell                - Build nushell + ALL system plugins (nu_plugin_*)"
    @echo "  build-nushell-debug          - Build nushell + system plugins (debug mode)"
    @echo "  build-nushell-target TARGET  - Build nushell + system plugins for specific target"
    @echo "  build-nushell-features FEAT  - Build nushell + system plugins with custom features"
    @echo "  build-nushell-deps           - Check nushell build dependencies"
    @echo "  build-nushell-info           - Show nushell build information"
    @echo ""
    @echo "  💡 NOTE: All 'build-nushell*' commands build the system plugins:"
    @echo "    nu_plugin_formats, nu_plugin_inc, nu_plugin_gstat, nu_plugin_query,"
    @echo "    nu_plugin_polars, nu_plugin_custom_values, nu_plugin_example, etc."
    @echo ""
    @echo "FULL BUILD WORKFLOWS:"
    @echo "  build-full                   - Build nushell + all plugins"
    @echo "  build-full-release           - Build full release distribution"
    @echo "  build-full-target TARGET     - Build full distribution for target"
    @echo "  build-full-cross             - Build full distribution for all targets"
    @echo ""
    @echo "FULL COLLECTION:"
    @echo "  collect-full                 - Collect all binaries (nushell + plugins)"
    @echo "  collect-full-debug           - Collect full binaries (debug mode)"
    @echo "  collect-full-list            - List available full binaries"
    @echo "  collect-full-platforms       - List available platforms"
    @echo "  collect-full-platform PLAT   - Collect for specific platform"
    @echo "  collect-full-all             - Collect for all platforms"
    @echo "  collect-plugins-only         - Collect only plugins (no nushell)"
    @echo ""
    @echo "FULL PACKAGING:"
    @echo "  pack-full                    - Create full distribution package"
    @echo "  pack-full-platform PLATFORM - Package for specific platform"
    @echo "  pack-full-all                - Package for all platforms"
    @echo "  pack-full-checksums          - Package with checksums"
    @echo "  pack-full-bootstrap          - Package with bootstrap installers"
    @echo "  pack-full-list               - Show what would be packaged"
    @echo ""
    @echo "FULL RELEASE WORKFLOWS:"
    @echo "  release-full                 - Complete full release workflow"
    @echo "  release-full-cross           - Cross-platform full release"
    @echo "  release-full-quick           - Quick full release (current platform)"
    @echo "  release-full-target TARGET   - Full release for specific target"
    @echo "  release-full-dev             - Development full release (debug)"
    @echo ""
    @echo "VERIFICATION:"
    @echo "  verify-full                  - Verify full installation"
    @echo "  test-install-full            - Test full installation locally"
    @echo "  verify-full-platform PLAT   - Verify platform installation"
    @echo ""
    @echo "INFORMATION:"
    @echo "  full-status                  - Show full distribution status"
    @echo "  full-help                    - Show this help"
    @echo ""
    @echo "EXAMPLES:"
    @echo "  just build-full-release"
    @echo "  just collect-full-all"
    @echo "  just pack-full-bootstrap"
    @echo "  just release-full-cross"
    @echo "  just verify-full"