# shellcheck shell=dash

___x_cmd_moonshot_count_token(){
    moonshot:debug "Sending request to moonshot count token"
    [ -z "$confirm_before_send" ] || {
        < "$request_body_file" ___x_cmd j2y | ___x_cmd bat -l yml >"$___X_CMD_DEVTTY_FP"
        ___x_cmd ui yesno "Do your want to send this message?" || {
            ___X_CMD_RETRY_ABORT=1
            return 1
        }
        confirm_before_send=
    }

    local request_body_file="${request_body_file}"
    local apikey=""; local endpoint=""; local proxy=""
    ___x_cmd_moonshot___get_apikey_endpoint_proxy_ || return $?

    moonshot:debug --request_body_file "$request_body_file"

    < "$request_body_file" ___x_cmd proxy runifset "$proxy" \
    ___x_cmd curl \
        -sS "$endpoint/v1/tokenizers/estimate-token-count"  \
        -H "Content-Type: application/json"                             \
        -H "Authorization: Bearer $apikey"                              \
        -d @-
}

___x_cmd_moonshot_count_token_app(){
    ___x_cmd_moonshot_count_token "$@" | ___x_cmd j2y
}