
xrc cfgy
___x_cmd_mthreads_cfg(){
    [ "$#" -gt 0 ] || {
        ___x_cmd_mthreads_init
        return
    }

    local op="$1"; shift
    case "$op" in
        -h|--help)      ___x_cmd help -m mthreads --cfg ;;
        *)              ___x_cmd_mthreads_cfg___invoke "$op" "$@" ;;
    esac
}


___x_cmd_mthreads_cur(){
    local X_help_cmd=; X_help_cmd='___x_cmd help -m mthreads --cur' help:arg:parse
    ___x_cmd_mthreads_cfg --current "$@"
}

___x_cmd_mthreads_init(){
    local cur_apikey=; local cur_codingplan_apikey=; local cur_model=; local cur_endpoint

    if [ -f "$(___x_cmd_mthreads_cur --get config)" ]; then
        ___x_cmd_mthreads_cur cur_apikey:=apikey  cur_codingplan_apikey:=codingplan_apikey  cur_model:=model  cur_endpoint:=endpoint 2>/dev/null
    fi

    mthreads:info --codingplan_apikey "https://coding-plan.kuaecloud.net/apikey" "To get MOORE THREADS API key -> https://coding-plan.kuaecloud.net/apikey"

    ___x_cmd_mthreads_cfg___invoke --init ${cur_apikey:+"--ctrl_exit_strategy"} \
        apikey              "Set up the MOORE THREADS API key"                  \
                            "$cur_apikey"   '=~*' "^[A-Za-z0-9-]+$" --          \
        codingplan_apikey   "Set up the MOORE THREADS Coding Plan API key"                  \
                            "$cur_codingplan_apikey"   '=~*' "^[A-Za-z0-9-]+$" --           \
        model               "Set up the MOORE THREADS API model"                                            \
                            "${cur_model:-"$___X_CMD_MTHREADS_DEFAULT_FIRST_MODEL"}" '=' GLM-4.7  --  \
        endpoint            "Set up the endpoint (optional)"                                \
                            "${cur_endpoint:-"$___X_CMD_MTHREADS_DEFAULT_ENDPOINT"}" || return $?
}


___X_CMD_MTHREADS_CFG_VARLIST="apikey,codingplan_apikey,model,endpoint"
___x_cmd_mthreads_cfg___invoke(){
    ___x_cmd_cfgy_obj   \
        --prefix            ___X_CMD_MTHREADS_CFG_DATA                \
        --default-config    "${___X_CMD_ROOT_CFG}/mthreads/X.cfg.yml" \
        --current-config    "${___X_CMD_MTHREADS_LOCAL_CONFIG}"       \
        --current-profile   "${___X_CMD_MTHREADS_LOCAL_PROFILE}"      \
        --varlist           "$___X_CMD_MTHREADS_CFG_VARLIST"          \
        "$@"
}


