package v1 import ( "net/http" "github.com/gin-gonic/gin" "github.com/gochat/gochat/internal/service" "github.com/gochat/gochat/pkg/response" ) // InboxLimitHandler handles inbox limit CRUD endpoints. // Reference: Chatwoot app/controllers/api/v1/accounts/inboxes/inbox_limits_controller.rb // Inbox limits only have create, update, and destroy actions (no index or show). type InboxLimitHandler struct { svc *service.InboxLimitService } // NewInboxLimitHandler creates a new InboxLimitHandler. func NewInboxLimitHandler(svc *service.InboxLimitService) *InboxLimitHandler { return &InboxLimitHandler{svc: svc} } // Create creates a new inbox limit. // POST /api/v1/accounts/:account_id/inboxes/:inbox_id/inbox_limits // Body: { "type": "conversation_count", "value": 100 } func (h *InboxLimitHandler) Create(c *gin.Context) { inboxID, err := parseUintParam(c, "inbox_id") if err != nil { response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid inbox_id") return } var req service.CreateInboxLimitRequest if err := c.ShouldBindJSON(&req); err != nil { response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid request body") return } limit, svcErr := h.svc.Create(c.Request.Context(), inboxID, req) if svcErr != nil { handleServiceError(c, svcErr) return } response.OK(c, limit) } // Update modifies an existing inbox limit. // PATCH /api/v1/accounts/:account_id/inboxes/:inbox_id/inbox_limits/:id // Body: { "type": "conversation_count", "value": 200 } func (h *InboxLimitHandler) Update(c *gin.Context) { id, err := parseUintParam(c, "id") if err != nil { response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id") return } var req service.UpdateInboxLimitRequest if err := c.ShouldBindJSON(&req); err != nil { response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid request body") return } limit, svcErr := h.svc.Update(c.Request.Context(), id, req) if svcErr != nil { handleServiceError(c, svcErr) return } response.OK(c, limit) } // Delete removes an inbox limit. // DELETE /api/v1/accounts/:account_id/inboxes/:inbox_id/inbox_limits/:id func (h *InboxLimitHandler) Delete(c *gin.Context) { id, err := parseUintParam(c, "id") if err != nil { response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id") return } if svcErr := h.svc.Delete(c.Request.Context(), id); svcErr != nil { handleServiceError(c, svcErr) return } response.OK(c, gin.H{}) }