# Build Module — Core build operations for ontoref
# =================================================

# Build all crates (all targets, all features)
build-all:
    @echo "Building all targets..."
    cargo build --all-targets

# Build ontoref-daemon in release mode and install
build-daemon: build-css
    cargo build --release -p ontoref-daemon --features "db,nats,ui,mcp,graphql"
    nu install/install.nu

# Build UnoCSS bundle for the daemon UI
build-css: sync-assets
    cd assets/css && pnpm install && pnpm run build

# Build without stratumiops dependencies (standalone)
build-standalone:
    cargo build -p ontoref-ontology
    cargo build -p ontoref-daemon --no-default-features

# Check all crates compile (fast feedback, no codegen)
check:
    cargo check --all-targets --all-features

# Generate a new GraphQL read token and print its Argon2id hash.
# Copy the TOKEN value to use in API calls; copy the HASH into config.ncl graphql.read_token_hash.
generate-graphql-token:
    #!/usr/bin/env bash
    set -euo pipefail
    TOKEN=$(openssl rand -base64 18 | tr -d '=/+' | head -c 24)
    HASH=$(ontoref-daemon --hash-password "$TOKEN")
    echo "TOKEN: $TOKEN"
    echo "HASH:  $HASH"
    echo ""
    echo "Add to ~/.config/ontoref/config.ncl:"
    echo "  graphql = { read_token_hash | String = \"$HASH\" },"

# Generate a new admin key-pair and print the Argon2id hash for config.ncl.
# Use ontoref-daemon --gen-keys for full key-pair generation with role assignment.
generate-admin-key:
    #!/usr/bin/env bash
    set -euo pipefail
    TOKEN=$(openssl rand -base64 18 | tr -d '=/+' | head -c 24)
    HASH=$(ontoref-daemon --hash-password "$TOKEN")
    echo "TOKEN: $TOKEN"
    echo "HASH:  $HASH"
    echo ""
    echo "Add to your project keys[] in config.ncl:"
    echo "  { role = 'admin, hash = \"$HASH\", label = \"admin\" },"
