package chat

import (
	"errors"
	"net/http"

	"hfb_sys/backend/pkg/response"

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

func writeChatError(c *gin.Context, err error) {
	switch {
	case errors.Is(err, ErrDependencyUnavailable):
		response.ServiceUnavailable(c, "聊天服务暂时不可用")
	case errors.Is(err, ErrConversationNotFound):
		response.Error(c, http.StatusNotFound, "chat_not_found", "会话不存在")
	case errors.Is(err, ErrPermissionDenied):
		response.Error(c, http.StatusForbidden, "permission_denied", "无权访问该会话")
	case errors.Is(err, ErrInvalidMessage):
		response.BadRequest(c, "消息内容不符合规则")
	default:
		response.Error(c, http.StatusInternalServerError, "internal_error", "聊天服务暂时不可用")
	}
}
