# shellcheck shell=dash

xrc:mod:lib     gh      model/chat model/ls
___x_cmd_gh_model(){
    param:void
    local ___X_CMD_GH_MODEL_DEFAULT_NAME="openai/gpt-4.1"
    local op="$1"
    case "$op" in
        ls|chat|get|set)
                    shift; ___x_cmd_gh_model_"$op" "$@" ;;
        --has-apikey)
                    ___x_cmd_gh_model_has_apikey ;;
        -h|--help)  ___x_cmd help -m gh model ;;
        *)          ___x_cmd help -m gh model >&2; return 64 ;;
    esac
}


___x_cmd_gh_model_get(){
    local X_help_cmd='___x_cmd help -m gh model get'; help:arg:parse
    local cur_model=""; ___x_cmd_gh_cur cur_model:=ai_model  2>/dev/null
    cur_model="${cur_model:-"$___X_CMD_GH_MODEL_DEFAULT_NAME"}"
    printf "%s\n" "$cur_model"
}

___x_cmd_gh_model_set(){
    local X_help_cmd='___x_cmd help -m gh model set'; help:arg-null:parse
    local model="$1"
    ___x_cmd_gh_cfg set ai_model="$model"
}

___x_cmd_gh_model_has_apikey(){
    local apikey=
    ___x_cmd gh --cur apikey:=token 2>/dev/null
    [ -n "$apikey" ] || {
        gh:error "Please setting up your github token first ==> 'x gh --cfg token=<your token>'"
        gh:warn "You can get the token from ==>  https://github.com/settings/tokens"
        return 1
    }
}