# shellcheck shell=dash

xrc:mod:lib     fjo     notification/ls         \
                        notification/ll         \
                        notification/info       \
                        notification/mark

___x_cmd_fjo_notification(){
    param:subcmd ___x_cmd_fjo_notification                                  \
        ls                  "Interactive UI show users's notification"      \
        ll                  "List users's notification threads"             \
        info                "Get notification thread by ID"                 \
        mark                "Mark notification as read by ID"

    param:subcmd:try
    param:run


    ___x_cmd_fjo_notification _param_help_doc
    return 1
}


___x_cmd_fjo_notification____ui_handler(){
    if [ -n "$ENFORCE_JSON" ] || [ -n "$json" ]; then
        ___x_cmd_cmds_cat
        ___x_cmd_fjo_http_error
        return
    fi
    (
        local msg="$1 notification success."
        local error_msg="$1 notification failure."
        case "$1" in
            Mark)
                ___x_cmd jo env . id=.number fjo_resp_err=.message \
                                Repo=.repository.full_name url=.repository.url
                ;;
            Info)
                ___x_cmd jo env id=.id Repo=.repository.full_name unread=.unread Url=.repository.url
                msg="Successfully get notification info."
                error_msg="Get notificationinfo failure."
                ;;
        esac
        if [ -n "$id" ]; then
            ___x_cmd_ui_tf true "$msg" "number: $id" ${Repo+"Repo: $Repo"} ${unread+"Unread: $Unread"} ${url+"Url: $Url"}
        else
            ___x_cmd_ui_tf false "$error_msg"
            ___x_cmd_fjo____handle_resp
            return 1
        fi
    )
}
