# shellcheck shell=sh disable=SC2039,SC3043,SC2120,SC2154
# reference:  https://developer.work.weixin.qq.com/document/path/91770#%E6%96%87%E6%9C%AC%E7%B1%BB%E5%9E%8B
# Reference:  https://open.work.weixin.qq.com/api/doc/90000/90135/90239

___x_cmd log init qywx
xrc param http ui arg
xrc:mod:lib qywx        type util cfg bot

___x_cmd_qywx___main(){
    arg:init qywx
    local ___X_CMD_QYWX_LOCAL_CONFIG="${___X_CMD_QYWX_LOCAL_CONFIG}"
    local ___X_CMD_QYWX_LOCAL_PROFILE="${___X_CMD_QYWX_LOCAL_PROFILE}"

    while [ $# -gt 0 ]; do
        case "${1}" in
            --config)       ___X_CMD_QYWX_LOCAL_CONFIG="$2";        arg:2:shift ;;
            @*)             ___X_CMD_QYWX_LOCAL_CONFIG="${1#@}";    shift       ;;
            --profile)      ___X_CMD_QYWX_LOCAL_PROFILE="$2";       arg:2:shift ;;
            :*)             ___X_CMD_QYWX_LOCAL_PROFILE="${1#:}";   shift       ;;
            *)              break;;
        esac
    done

    param:advise qywx
    param:subcmd ___x_cmd_qywx                                  \
        bot             "qywx bot"                              \
        --cfg           "manage configuration for qywx"         \
        --cur           "current configuration for qywx"        \
        init            "Interactive UI init configuration"
    param:subcmd:try

    param:subcmd ___x_cmd_qywx_bot               \
        send             "seng msg"
    param:subcmd:try
    # member          "member manage"
    # department      "department manage"
    # auth            "Manage qywx authentication state"

    param:run

    if [ "$#" -eq 0 ]; then
        ___x_cmd_qywx --help
    else
        ___x_cmd_qywx bot send "$@"
    fi
    return
}

___x_cmd_qywx_help(){
    ___x_cmd help -m qywx "$@" >&2
}
