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"
)

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

// NewConfigStoreManager creates a new instance of ConfigStoreManager with ratelimiter.
func NewConfigStoreManager(
	wrapped persistence.ConfigStoreManager,
	rateLimiter quotas.Limiter,
) persistence.ConfigStoreManager {
	return &ratelimitedConfigStoreManager{
		wrapped:     wrapped,
		rateLimiter: rateLimiter,
	}
}

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

func (c *ratelimitedConfigStoreManager) FetchDynamicConfig(ctx context.Context, cfgType persistence.ConfigType) (fp1 *persistence.FetchDynamicConfigResponse, err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.FetchDynamicConfig(ctx, cfgType)
}

func (c *ratelimitedConfigStoreManager) UpdateDynamicConfig(ctx context.Context, request *persistence.UpdateDynamicConfigRequest, cfgType persistence.ConfigType) (err error) {
	if ok := c.rateLimiter.Allow(); !ok {
		err = ErrPersistenceLimitExceeded
		return
	}
	return c.wrapped.UpdateDynamicConfig(ctx, request, cfgType)
}
