package regionalapi

import (
	"net/http"

	"github.com/tidbcloud/observability/pkg/regionalservice"

	"github.com/tidbcloud/observability/pkg/regionalapi/apiinterceptor"

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

// ServiceInfo
// @Summary get service info
// @Description get service info
// @Tags service
// @Accept json
// @Produce json
// @Success 200 {object} message.Result{data=message.GetServiceInfoResp}
// @Failure 500 {object} message.Result
// @Router / [get]
func ServiceInfo(c *gin.Context) {
	resp, err := regionalservice.GetServiceHandler().ServiceInfo(c)
	if err != nil {
		apiinterceptor.Fail(c, err)
	} else {
		apiinterceptor.Succeed(c, http.StatusOK, resp)
	}
}

// ServiceHealth
// @Summary get service health
// @Description get service health
// @Tags service
// @Accept json
// @Produce json
// @Success 200 {object} message.Result{data=message.GetServiceHealthResp}
// @Failure 500 {object} message.Result
// @Router /health [get]
func ServiceHealth(c *gin.Context) {
	req := &message.GetServiceHealthReq{}
	if ok := apiinterceptor.HandleJsonRequestFromQuery(c, req); ok {
		apiinterceptor.Succeed(c, http.StatusOK, message.GetServiceHealthResp{
			ServiceHealth: true,
		})
	}
}
