# shellcheck shell=dash

___x_cmd_wkp_api_page(){
    :
}

# srinfo: totalhits|suggestion|rewrittenquery
# https://www.mediawiki.org/wiki/API:Search
___x_cmd_wkp_api_search(){
    local proxy;  local limit; local srinfo; local sort; local str
    ___x_cmd_wkp_cur proxy:= 2>/dev/null

    while [ $# -gt 0 ]; do
        case "$1" in
            --str)       str="$2";      [ $# -ge 2 ] || N=wkp M="Please provide str value"       log:ret:64; shift 2 ;;
            --limit)     limit="$2";    [ $# -ge 2 ] || N=wkp M="Please provide limit value"     log:ret:64; shift 2 ;;
            --sort)      sort="$2";     [ $# -ge 2 ] || N=wkp M="Please provide sort value"      log:ret:64; shift 2 ;;
            --srinfo)    srinfo="$2";   [ $# -ge 2 ] || N=wkp M="Please provide srinfo value"    log:ret:64; shift 2 ;;
            *)           break;;
        esac
    done

    limit="${limit:-10}"
    sort="${sort:-relevance}"

    local data
    data="$(
        ___x_cmd curl gencode action==query list==search   \
            srsearch=="$str" ${srinfo:+srinfo=="$srinfo"}      \
            srlimit=="$limit" srsort=="$sort" format==json
    )"
    wkp:debug "request body[$data]"

    ___x_cmd ccmd 10d -- eval x curl -sS \
        ${proxy:+-x} ${proxy:+"$proxy"} \
        -G "$data" \
        "$___X_CMD_WKP_API_URL"
}
