# ╔══════════════════════════════════════════════════════════════════════╗
# ║                      BUILD RECIPES                                   ║
# ║            Build workspace with different feature flags              ║
# ╚══════════════════════════════════════════════════════════════════════╝

# === FEATURE FLAGS ===
FEATURES_CORE_DEFAULT := "filesystem"
FEATURES_CORE_FULL := "filesystem,surrealdb,fastembed,full"
FEATURES_CORE_STORAGE := "filesystem,surrealdb"
FEATURES_CORE_EMBEDDINGS := "filesystem,fastembed"

# Help for build module
help:
    @echo "BUILD MODULE"
    @echo ""
    @echo "Build default (filesystem backend):"
    @echo "  just build::default"
    @echo ""
    @echo "Build specific components:"
    @echo "  just build::core        Build kogral-core library"
    @echo "  just build::cli         Build kogral-cli binary"
    @echo "  just build::mcp         Build kogral-mcp server"
    @echo ""
    @echo "Build with features:"
    @echo "  just build::core-full   Build kogral-core with all features"
    @echo "  just build::core-db     Build kogral-core with SurrealDB"
    @echo "  just build::core-ai     Build kogral-core with fastembed"
    @echo ""
    @echo "Build combined:"
    @echo "  just build::all         Build all crates"
    @echo "  just build::workspace   Build entire workspace"
    @echo ""
    @echo "Build release:"
    @echo "  just build::release     Release build (all features)"
    @echo ""
    @echo "Check compilation:"
    @echo "  just build::check       Check without building"

# === DEFAULT BUILD ===

# Build workspace with default features
[doc("Build default: filesystem backend only")]
default:
    @echo "=== Building default features ==="
    cargo build --workspace

# === COMPONENT BUILDS ===

# Build kogral-core library
[doc("Build kogral-core library (default features)")]
core:
    @echo "=== Building kogral-core ==="
    cargo build --package kogral-core

# Build kogral-cli binary
[doc("Build kogral-cli command-line tool")]
cli:
    @echo "=== Building kogral-cli ==="
    cargo build --package kogral-cli

# Build kogral-mcp server
[doc("Build kogral-mcp MCP server")]
mcp:
    @echo "=== Building kogral-mcp ==="
    cargo build --package kogral-mcp

# === FEATURE-SPECIFIC BUILDS ===

# Build kogral-core with all features
[doc("Build kogral-core with all features (filesystem, surrealdb, fastembed)")]
core-full:
    @echo "=== Building kogral-core (all features) ==="
    cargo build --package kogral-core --features {{ FEATURES_CORE_FULL }}

# Build kogral-core with SurrealDB backend
[doc("Build kogral-core with SurrealDB support")]
core-db:
    @echo "=== Building kogral-core (SurrealDB) ==="
    cargo build --package kogral-core --features {{ FEATURES_CORE_STORAGE }}

# Build kogral-core with fastembed
[doc("Build kogral-core with local embeddings (fastembed)")]
core-ai:
    @echo "=== Building kogral-core (fastembed) ==="
    cargo build --package kogral-core --features {{ FEATURES_CORE_EMBEDDINGS }}

# === COMBINED BUILDS ===

# Build all crates
[doc("Build all crates (kogral-core, kogral-cli, kogral-mcp)")]
all:
    @echo "=== Building all crates ==="
    @just build::core
    @just build::cli
    @just build::mcp
    @echo "✓ All crates built"

# Build entire workspace
[doc("Build entire workspace with all features")]
workspace:
    @echo "=== Building workspace (all features) ==="
    cargo build --workspace --all-features

# === RELEASE BUILD ===

# Build release version with all features
[doc("Build release version (optimized, all features)")]
release:
    @echo "=== Building release (all features) ==="
    cargo build --workspace --all-features --release
    @echo "✓ Release build complete"
    @ls -lh target/release/kogral-cli target/release/kogral-mcp 2>/dev/null || true

# === VALIDATION ===

# Check compilation without building
[doc("Check code compiles without building artifacts")]
check:
    @echo "=== Checking compilation ==="
    cargo check --workspace --all-features
    @echo "✓ Compilation check passed"
