package ratelimited

// Code generated by gowrap. DO NOT EDIT.
// template: ../templates/ratelimited.tmpl
// gowrap: http://github.com/hexdigest/gowrap

import (
	"context"

	"github.com/uber/cadence/common/persistence"
	"github.com/uber/cadence/common/quotas"
)

// ratelimitedQueueManager implements persistence.QueueManager interface instrumented with rate limiter.
type ratelimitedQueueManager struct {
	wrapped     persistence.QueueManager
	rateLimiter quotas.Limiter
}

// NewQueueManager creates a new instance of QueueManager with ratelimiter.
func NewQueueManager(
	wrapped persistence.QueueManager,
	rateLimiter quotas.Limiter,
) persistence.QueueManager {
	return &ratelimitedQueueManager{
		wrapped:     wrapped,
		rateLimiter: rateLimiter,
	}
}

func (c *ratelimitedQueueManager) Close() {
	c.wrapped.Close()
	return
}

func (c *ratelimitedQueueManager) DeleteMessageFromDLQ(ctx context.Context, messageID int64) (err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.DeleteMessageFromDLQ(ctx, messageID)
}

func (c *ratelimitedQueueManager) DeleteMessagesBefore(ctx context.Context, messageID int64) (err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.DeleteMessagesBefore(ctx, messageID)
}

func (c *ratelimitedQueueManager) EnqueueMessage(ctx context.Context, messagePayload []byte) (err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.EnqueueMessage(ctx, messagePayload)
}

func (c *ratelimitedQueueManager) EnqueueMessageToDLQ(ctx context.Context, messagePayload []byte) (err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.EnqueueMessageToDLQ(ctx, messagePayload)
}

func (c *ratelimitedQueueManager) GetAckLevels(ctx context.Context) (m1 map[string]int64, err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.GetAckLevels(ctx)
}

func (c *ratelimitedQueueManager) GetDLQAckLevels(ctx context.Context) (m1 map[string]int64, err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.GetDLQAckLevels(ctx)
}

func (c *ratelimitedQueueManager) GetDLQSize(ctx context.Context) (i1 int64, err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.GetDLQSize(ctx)
}

func (c *ratelimitedQueueManager) RangeDeleteMessagesFromDLQ(ctx context.Context, firstMessageID int64, lastMessageID int64) (err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.RangeDeleteMessagesFromDLQ(ctx, firstMessageID, lastMessageID)
}

func (c *ratelimitedQueueManager) ReadMessages(ctx context.Context, lastMessageID int64, maxCount int) (q1 persistence.QueueMessageList, err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.ReadMessages(ctx, lastMessageID, maxCount)
}

func (c *ratelimitedQueueManager) ReadMessagesFromDLQ(ctx context.Context, firstMessageID int64, lastMessageID int64, pageSize int, pageToken []byte) (qpa1 []*persistence.QueueMessage, ba1 []byte, err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.ReadMessagesFromDLQ(ctx, firstMessageID, lastMessageID, pageSize, pageToken)
}

func (c *ratelimitedQueueManager) UpdateAckLevel(ctx context.Context, messageID int64, clusterName string) (err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.UpdateAckLevel(ctx, messageID, clusterName)
}

func (c *ratelimitedQueueManager) UpdateDLQAckLevel(ctx context.Context, messageID int64, clusterName string) (err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.UpdateDLQAckLevel(ctx, messageID, clusterName)
}
