# shellcheck shell=bash
# https://gitee.com/api/v5/swagger#/getV5NotificationsThreads
___x_cmd_gt_notification_ls() {
    if ___x_cmd_gx_has_format_args "$@"; then
        ___x_cmd_gt_notification_ls "$@"
        return
    fi

    param:scope     ___x_cmd_gt
    param:dsl       '
options:
    --unread            "only get unread messages"                                                           <>:Boolean="true"
    --participating     "shows notifications in which the user is directly participating or mentioned"       <>:Boolean="false"
    --type              "Filter notifications of specified types"                                            <>=all             = all event referer
    --since             "show results that were last updated after the given time"                           <>:ISOTime=""
    --before            "show notifications updated before the given time"                                   <>:ISOTime=""
    --ids               "Specify a set of notification IDs separated by"                                     <>=""

    --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_GT_TUI_TABLE_REQUSET_DATA=''
        ___x_cmd_gt_tui_app --unread "$unread"  --participating "$participating" --since "$since" --before "$before" --per_page "$per_page" --page "$page" --type "$type" --ids "$ids" \
            --request-code '___x_cmd_gt_notification_ll___raw'  \
            --error-msg "Get notification list fail"           \
            --end ___x_cmd_gt_notification_app_status_handler \
            "notification.app.awk"
    else
        ___x_cmd_gt_notification_ls___raw | \
             ___x_cmd jo 2c .id .repository .unread .url
    fi
}


___x_cmd_gt_notification_ll___raw(){
    ___x_cmd_gt_get_multi "/notifications/threads"  unread participating type since before ids
}

___x_cmd_gt_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_gt_notification_mark    "${id}"                         ;;
            *)              return   ;;
    esac

}


