# shellcheck shell=dash

# GET /api/v1/resolve?slug=&hash=
___x_cmd_clawhub_skill_resolve(){
    case "$1" in -h|--help) shift; ___x_cmd help -m clawhub resolve "$@" ; return 0 ;; esac

    local slug=; local hash=
    while [ $# -gt 0 ]; do
        case "$1" in
            --slug)  slug="$2";  shift 2 ;;
            --hash)  hash="$2";  shift 2 ;;
            *)  [ -z "$slug" ] && slug="$1" || { clawhub:error "Unexpected arg: $1"; return 1; }; shift ;;
        esac
    done

    [ -n "$slug" ] || M='Provide skill slug' N=clawhub log:ret:64
    [ -n "$hash" ] || M='Provide version hash (--hash)' N=clawhub log:ret:64

    local qs="slug=$(___x_cmd url encode "$slug")&hash=$(___x_cmd url encode "$hash")"

    local resp=
    resp="$(___x_cmd_clawhub_u_curl get "/api/v1/resolve?$qs" --no-auth)" || {
        ___x_cmd_clawhub_u_handle_resp false "Failed to resolve '$slug':"
        return 1
    }
    printf "%s\n" "$resp"
}
