# shellcheck shell=bash  disable=2034
xrc cfgy
___x_cmd_hn_cfg(){
    [ "$#" -gt 0 ] || {
        _____x_cmd_hn_help --cfg
        return 64
    }

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

___x_cmd_hn_cur(){
    local X_help_cmd=; X_help_cmd='x help -m hn --cur' help:arg:parse
    ___x_cmd_hn_cfg___invoke --current "$@"
}


___x_cmd_hn_init(){
    local X_help_cmd=; X_help_cmd='x help -m hn --init' help:arg:parse
    local cur_story_timeout=; local cur_index_timeout=; local cur_datadir=; local cur_proxy=
    if [ -f "$(___x_cmd_hn_cur --get config)" ]; then
        ___x_cmd_hn_cur cur_story_timeout:=story_timeout cur_index_timeout:=index_timeout cur_datadir:=datadir cur_proxy:=proxy
    fi

    ___x_cmd_hn_cfg___invoke --init \
        story_timeout       "Set up timeout for story"           "${cur_story_timeout:-"$___X_CMD_HN_DEFAULT_STORY_TIMEOUT"}"   --  \
        index_timeout       "Set up timeout for index"           "${cur_index_timeout:-"$___X_CMD_HN_DEFAULT_INDEX_TIMEOUT"}"   --  \
        datadir             "set up datadir"                     "${cur_datadir:-"$___X_CMD_HN_CACHE_STORE"}"                   --  \
        proxy               "Set up the network proxy for API requests"     "${cur_proxy}"      '=~'    "^([a-z0-9]+://)?[A-Za-z0-9.:]*$" -- || return $?
}


___X_CMD_HN_CFG_VARLIST="story_timeout,index_timeout,datadir,proxy"
___x_cmd_hn_cfg___invoke(){
    # shellcheck disable=2154
    ___x_cmd_cfgy_obj   \
        --prefix            ___X_CMD_HN_CFG_DATA                \
        --default-config    "${___X_CMD_ROOT_CFG}/hn/X.cfg.yml" \
        --current-config    "${___X_CMD_HN_LOCAL_CONFIG}"       \
        --current-profile   "${___X_CMD_HN_LOCAL_PROFILE}"      \
        --varlist           "${___X_CMD_HN_CFG_VARLIST}"        \
        "$@"
}
