#!/usr/bin/env bash
# Source after setting BEAGLE_STORE_OUT, then call find_store_resolver.

find_store_resolver() {
    local store_root candidate
    store_root="$(dirname "$BEAGLE_STORE_OUT")"

    for candidate in \
        "$BEAGLE_STORE_OUT/resolve.clj" \
        "$store_root/resolve.clj"
    do
        if [[ -f "$candidate" ]]; then
            printf '%s\n' "$candidate"
            return 0
        fi
    done

    echo "Beagle Store resolver not found; checked:" >&2
    echo "  $BEAGLE_STORE_OUT/resolve.clj" >&2
    echo "  $store_root/resolve.clj" >&2
    return 1
}
