package repositories import ( "agent-desk/internal/models" "agent-desk/internal/pkg/enums" "gorm.io/gorm" ) // FindPendingDispatchBatch returns a bounded, checked page. A failed read must // not be mistaken for an empty queue by setup or the periodic dispatcher. func (r *conversationRepository) FindPendingDispatchBatch(db *gorm.DB, limit int) ([]models.Conversation, error) { conversations := make([]models.Conversation, 0) err := db.Where("status = ? AND current_assignee_id = ?", enums.IMConversationStatusPending, 0). Order("id DESC").Limit(limit).Find(&conversations).Error return conversations, err }