# shellcheck shell=dash

xrc cfgy
___x_cmd_discord_cfg(){
    param:void
    [ "$#" -gt 0 ] || {
        _____x_cmd_discord_help --cfg
        return 64
    }

    local X_help_cmd=; X_help_cmd='x help -m discord --cfg' help:arg:parse
    ___x_cmd_discord_cfg___invoke "$@"
}

___x_cmd_discord_cur(){
    param:void
    local X_help_cmd=; X_help_cmd='x help -m discord --cur' help:arg:parse
    ___x_cmd_discord_cfg___invoke --current "$@"
}

___x_cmd_discord_init(){
    param:void

    local cur_webhook=; local cur_proxy=; local cur_bot_token=;
    if [ -f "$(___x_cmd_discord_cur --get config)" ]; then
        ___x_cmd_discord_cur cur_webhook:=webhook cur_proxy:=proxy cur_bot_token:=bot_token cur_guild_id:=guild_id 2>/dev/null
    fi

    local X_help_cmd=; X_help_cmd='x help -m discord --init' help:arg:parse
    ___x_cmd_discord_cfg___invoke --init \
        webhook     "Set webhook URL of the bot (optional)"                   "$cur_webhook"      "=~*" "^https://discord.com/api/webhooks/.*" -- \
        proxy       "Set up the network proxy for API requests (optional)"  "${cur_proxy}"      "=~" "^([a-z0-9]+://)?[0-9.:]+$" -- \
        bot_token   "Set Discord bot token"                                  "${cur_bot_token}"  "=~*" "^Bot .+$"
}

___X_CMD_DISCORD_CFG_VARLIST="webhook,proxy,bot_token"
___x_cmd_discord_cfg___invoke(){
    ___x_cmd_cfgy_obj \
        --prefix            ___X_CMD_discord_CFG_DATA                  \
        --default-config    "${___X_CMD_ROOT_CFG}/discord/X.cfg.yml"   \
        --current-config    "${___X_CMD_DISCORD_LOCAL_CONFIG}"         \
        --current-profile   "${___X_CMD_DISCORD_LOCAL_PROFILE}"        \
        --varlist           "$___X_CMD_DISCORD_CFG_VARLIST"            \
        "$@"
}