# shellcheck shell=sh disable=SC3043,2034

# using a csv app

# Using ls_remote
___x_cmd_llmf_model_la(){
    local format=app
    while [ $# -gt 0 ]; do
        case "$1" in
            -j|--json)      format=json     ;;
            -c|--csv)       format=csv      ;;
            --app)          format=app      ;;

            -h|--help)      ___x_cmd help -m llmf model la; return ;;
            *)              break ;;
        esac
        shift
    done

    ___x_cmd_llmf_model_la___"$format"
}

___x_cmd_llmf_model_la___csv(){
    ___x_cmd_llmf_model_ls___csv --all
}

___x_cmd_llmf_model_la___json(){
    ___x_cmd_llmf_model_ls___json --all
}

___x_cmd_llmf_model_la___app(){
    local model=
    local x_=""; ___x_cmd_llmf_model_ls___app_ --all || return $?
    model="$x_"
    [ "$model" ] || return $?
    llmf:info "Selected model -> $model"
    local id=
    ___x_cmd ui select id "Next"   \
       "Setting the default [model=$model]" \
       "Download the [model=$model]" \
       "Get [model=$model] information" \
       "EXIT" || return $?

    case "$id" in
        1)
            ___x_cmd_llmf_model_default set "$model" || return $?

            ___x_cmd_llmf_model_exist "$model" || {
                llmf:info "cmd -> \`x llmf model download $model\`"
                if ___x_cmd ui yesno "Do you want to download [mode=$model] ?"; then
                    ___x_cmd_llmf_model_download "$model" || return $?
                fi
            }
            ;;
        2)  ___x_cmd_llmf_model_download "$model" || return $? ;;
        3)  ___x_cmd_llmf_model_info "$model" || return $? ;;
        *)  return ;;
    esac

    x_=; ___x_cmd_llmf_model_default get_
    llmf:info "Current default model is ${x_:-"undefined"}"
}
