# shellcheck shell=dash

___x_cmd_claude_siliconflow(){
    local op="$1"
    case "$op" in
        -h|--help)      ___x_cmd help -m claude siliconflow; return 0 ;;
        --cfg)          ___x_cmd siliconflow --cfg "$@";     return 0 ;;
        --)             shift ;;
    esac

    local model=""
    local apikey=""
    local endpoint="https://api.siliconflow.cn/"
    local x_=""

    claude:provider:fetch:init
    ___x_cmd_claude_sili___fetch_   || return $?

    ANTHROPIC_API_KEY="" API_TIMEOUT_MS="$x_timeout"        \
        ___x_cmd_claude_other___use     siliconflow                \
        "$x_url" "$x_apikey" "$x_model" "$x_fastmodel" "$x_nonessential_traffic" "$x_effortlevel" "$@"
}

___x_cmd_claude_sili___fetch_(){
    local model=""
    local apikey=""
    local endpoint="https://api.siliconflow.cn/"

    ___x_cmd siliconflow --cur model:= apikey:= endpoint:= 2>/dev/null

    [ -n "$apikey" ] || {
        claude:warn \
            --tip1 'x siliconflow --cfg'                           \
            --tip2 'x siliconflow --cfg apikey=<YOUR-API-KEY>'     \
            "Please setup siliconflow API-KEY."

        if ___x_cmd_runmode_allow_manual; then
            ___x_cmd siliconflow --cfg || return $?
            ___x_cmd siliconflow --cur model:= apikey:= endpoint:= 2>/dev/null
        fi
        [ -n "$apikey" ] || N=claude M="Failed to retrieve API-KEY. Please check your configuration." log:ret:1
    }

    x_url="$endpoint"
    x_apikey="$apikey"

    x_model="${model}"
    [ -n "$x_model" ] || x_model="moonshotai/Kimi-K2-Instruct-0905"

    x_fastmodel="${x_model}"
    x_effortlevel=auto

    x_timeout="${API_TIMEOUT_MS:-"3000000"}"
}
