# shellcheck    shell=dash disable=SC2154,SC2034
xrc cfgy

___x_cmd_bwh_cfg(){
    [ "$#" -gt 0 ] || {
        ___x_cmd_bwh_init
        return
    }

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

___x_cmd_bwh_cur(){
    local X_help_cmd=; X_help_cmd='___x_cmd help -m bwh --cur' help:arg:parse
    ___x_cmd_bwh_cfg --current "$@"
}

___x_cmd_bwh_init(){
    local cur_veid=; local cur_apikey=
    if [ -f "$(___x_cmd_bwh_cur --get config)" ]; then
        ___x_cmd_bwh_cur cur_veid:=veid cur_apikey:=apikey
    fi

    # TODO:
    bwh:info "Open the bandwagon official for API key -> https://..."

    ___x_cmd_bwh_cfg___invoke --init --ctrl_exit_strategy                         \
        veid        "Set up the veid key of bwh key"      "$cur_veid"             \
                        '=~'    "^[A-Za-z0-9-]+$"           --                    \
        apikey      "Set up the apikey of bwh key"        "$cur_apikey"           \
                        '=~*'   "^[A-Za-z0-9_-]+$"           --                   \
        proxy       "Set up the network proxy for API requests (optional)"        \
                    "$cur_proxy" '=~'    "^([a-z0-9]+://)?[0-9.:]+$" --
}

___X_CMD_BWH_CFG_VARLIST="apikey,veid,proxy"
___x_cmd_bwh_cfg___invoke(){
    ___x_cmd_cfgy_obj                                               \
        --prefix            ___X_CMD_BWH_CFG_DATA                   \
        --default-config    "${___X_CMD_ROOT_CFG}/bwh/X.cfg.yml"    \
        --current-config    "${___X_CMD_BWH_LOCAL_CONFIG}"          \
        --current-profile   "${___X_CMD_BWH_LOCAL_PROFILE}"         \
        --varlist           "${___X_CMD_BWH_CFG_VARLIST}"           \
        "$@"
}

