package api

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

// lsNotifications godoc
// @Summary List notifications
// @Description Lists all notifications generated by thread and account activity.
// @Tags notifications
// @Produce application/json
// @Success 200 {object} pb.NotificationList "notifications"
// @Router /notifications [get]
func (a *Api) lsNotifications(g *gin.Context) {
	pbJSON(g, http.StatusOK, a.Node.Notifications("", -1))
}

// readNotifications godoc
// @Summary Mark notifiction as read
// @Description Marks a notifiction as read by ID. Use 'all' to mark all as read.
// @Tags notifications
// @Produce application/json
// @Param id path string true "notification id"
// @Success 200 {string} string "ok"
// @Failure 400 {string} string "Bad Request"
// @Router /notifications/{id}/read [post]
func (a *Api) readNotifications(g *gin.Context) {
	id := g.Param("id")

	var err error
	if id == "all" {
		err = a.Node.ReadAllNotifications()
	} else {
		err = a.Node.ReadNotification(id)
	}
	if err != nil {
		g.String(http.StatusBadRequest, err.Error())
		return
	}

	g.JSON(http.StatusOK, "ok")
}
