package api

import (
	"net/http"

	"github.com/gin-gonic/gin"
	oncallapi "github.com/tidbcloud/aisupport/packages/sdk-go/contracts/api/oncall"
)

const (
	ErrorCodeInvalidArgument  = oncallapi.ErrorCodeInvalidArgument
	ErrorCodeUnauthenticated  = oncallapi.ErrorCodeUnauthenticated
	ErrorCodePermissionDenied = oncallapi.ErrorCodePermissionDenied
	ErrorCodeTeamNotFound     = oncallapi.ErrorCodeTeamNotFound
	ErrorCodeInternal         = oncallapi.ErrorCodeInternal
)

type ErrorResponse = oncallapi.ErrorResponse

func respondError(c *gin.Context, status int, code, message string) {
	c.JSON(status, ErrorResponse{Code: code, Message: message, Error: message})
}

func respondInternalError(c *gin.Context) {
	respondError(c, http.StatusInternalServerError, ErrorCodeInternal, "internal server error")
}
