# shellcheck shell=bash
# https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user
___x_cmd_gh_notification_ls() {
    if ___x_cmd_gx_has_format_args "$@"; then
        ___x_cmd_gh_notification_ll "$@"
        return
    fi
    param:scope     ___x_cmd_gh
    param:dsl       '
options:
    --all               "show notifications marked as read"                                                  <>:boolean="false"
    --participating     "shows notifications in which the user is directly participating or mentioned"       <>:boolean="false"
    --since             "show results that were last updated after the given time"                           <>:ISOTime=""
    --before            "show notifications updated before the given time"                                   <>:ISOTime=""

    --per_page          "Results per page"                                                                   <>:Numbers="30"
    --page              "Page number of the results to fetch."                                               <>:Numbers="1"

    --json|-j           "output origin json data"
    --csv               "output csv data"
    --yml               "output yml data"
'
    param:run

    if ___x_cmd_gx_is_interactive_env; then
        local ___X_CMD_TUI_TABLE_FINAL_COMMAND
        local ___X_CMD_TUI_TABLE_CUR_LINE
        local ___X_CMD_TUI_TABLE_CUR_ITEM
        local ___X_CMD_GH_TUI_TABLE_REQUSET_DATA=''
        ___x_cmd_gh_tui_app --all "$all"  --participating "$participating" --since "$since" --before "$before" --per_page "$per_page" --page "$page"  \
            --request-code '___x_cmd_gh_notification_ll___raw'  \
            --error-msg "Get notification list fail"           \
            --end ___x_cmd_gh_notification_app_status_handler \
            "notification.app.awk"
    else
        ___x_cmd_gh_notification_ls___raw | \
             ___x_cmd jo 2c .id .repository .unread .url
    fi
}

___x_cmd_gh_notification_ll___raw(){
    ___x_cmd_gh_get_multi "/notifications" per_page page  all since before participating
}

___x_cmd_gh_notification_app_status_handler(){
    case "$___X_CMD_TUI_TABLE_FINAL_COMMAND" in
            "ENTER")        printf "%s\n" "${___X_CMD_TUI_TABLE_CUR_LINE}"                   ;;
            "m")            local id="${___X_CMD_TUI_TABLE_CUR_LINE##*ID: }"
                            id="${id%%
Repo:*}"
                            ___x_cmd_gh_notification_mark    "${id}"                        ;;
            *)              return   ;;
    esac
}