# shellcheck shell=bash
# https://codeberg.org/api/swagger#/notification/notifyGetList
___x_cmd_fjo_notification_ls() {
    if ___x_cmd_gx_has_format_args "$@"; then
        ___x_cmd_fjo_notification_ll "$@"
        return
    fi

    param:scope     ___x_cmd_fjo
    param:dsl       '
options:
    --all               "show notifications marked as read"                           <>:Bool="false"
    --since             "Only show items updated after the given time"                <>=""
    --before            "Only show items updated before the given time"               <>=""

    --limit             "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_FJO_TUI_TABLE_REQUSET_DATA=''
        ___x_cmd_fjo_tui_app --all "$all" --since "$since" --before "$before" --limit "$limit" --page "$page" --___X_CMD_FCT_API_VENDOR "$___X_CMD_FCT_API_VENDOR" \
            --request-code '___x_cmd_fjo_notification_ls___raw'  \
            --error-msg "Get notification list fail"           \
            --end ___x_cmd_fjo_notification_app_status_handler \
            "notification.app.awk"
    else
        ___x_cmd_fjo_notification_ls___raw | \
             ___x_cmd jo 2c .id .repository .unread .url
    fi
}

___x_cmd_fjo_notification_ls___raw(){
    ___x_cmd_fjo_get_multi "/notifications" limit page  all since before
}

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