package regionalapi

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/tidbcloud/observability/pkg/common/message"
	"github.com/tidbcloud/observability/pkg/regionalapi/apiinterceptor"
	"github.com/tidbcloud/observability/pkg/regionalservice"
)

// ListClusterAlerts
// @Summary list cluster alerts
// @Description list all user alerts belongs to specific cluster
// @Tags external
// @Accept json
// @Produce json
// @Param bizType path string true "bizType, for staging, use staging-tidbcloud, others, use tidbcloud"
// @Param tenantID path string true "tenant id"
// @Param projectID path string true "project id"
// @Param applicationID path string true "application id"
// @Param request query message.QueryExternalAlertsReq true "Query Alerts Parameters"
// @Success 200 {object} message.Result{data=message.QueryExternalAlertsResp}
// @Failure 400 {object} message.Result
// @Failure 404 {object} message.Result
// @Failure 500 {object} message.Result
// @Router /external/{bizType}/orgs/{tenantID}/projects/{projectID}/clusters/{applicationID}/alerts [get]
func ListClusterExternalAlerts(c *gin.Context) {
	req := &message.QueryExternalAlertsReq{
		BizType:       c.Param("bizType"),
		TenantID:      c.Param("tenantID"),
		ProjectID:     c.Param("projectID"),
		ApplicationID: c.Param("applicationID"),
	}
	if ok := apiinterceptor.HandleJsonRequestFromQuery(c, req); ok {
		resp, err := regionalservice.GetHandler().ListClusterExternalAlerts(c, *req)
		if err != nil {
			apiinterceptor.Fail(c, err)
		} else {
			apiinterceptor.Succeed(c, http.StatusOK, resp)
		}
	}
}
