package metered

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

import (
	"context"

	"github.com/uber/cadence/common/config"
	"github.com/uber/cadence/common/log"
	"github.com/uber/cadence/common/metrics"
	"github.com/uber/cadence/common/persistence"
)

// meteredTaskManager implements persistence.TaskManager interface instrumented with rate limiter.
type meteredTaskManager struct {
	base
	wrapped persistence.TaskManager
}

// NewTaskManager creates a new instance of TaskManager with ratelimiter.
func NewTaskManager(
	wrapped persistence.TaskManager,
	metricClient metrics.Client,
	logger log.Logger,
	cfg *config.Persistence,
) persistence.TaskManager {
	return &meteredTaskManager{
		wrapped: wrapped,
		base: base{
			metricClient:                  metricClient,
			logger:                        logger,
			enableLatencyHistogramMetrics: cfg.EnablePersistenceLatencyHistogramMetrics,
		},
	}
}

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

func (c *meteredTaskManager) CompleteTask(ctx context.Context, request *persistence.CompleteTaskRequest) (err error) {
	op := func() error {
		err = c.wrapped.CompleteTask(ctx, request)
		c.emptyMetric("TaskManager.CompleteTask", request, err, err)
		return err
	}

	err = c.call(metrics.PersistenceCompleteTaskScope, op, getCustomMetricTags(request)...)
	return
}

func (c *meteredTaskManager) CompleteTasksLessThan(ctx context.Context, request *persistence.CompleteTasksLessThanRequest) (cp1 *persistence.CompleteTasksLessThanResponse, err error) {
	op := func() error {
		cp1, err = c.wrapped.CompleteTasksLessThan(ctx, request)
		c.emptyMetric("TaskManager.CompleteTasksLessThan", request, cp1, err)
		return err
	}

	err = c.call(metrics.PersistenceCompleteTasksLessThanScope, op, getCustomMetricTags(request)...)
	return
}

func (c *meteredTaskManager) CreateTasks(ctx context.Context, request *persistence.CreateTasksRequest) (cp1 *persistence.CreateTasksResponse, err error) {
	op := func() error {
		cp1, err = c.wrapped.CreateTasks(ctx, request)
		c.emptyMetric("TaskManager.CreateTasks", request, cp1, err)
		return err
	}

	err = c.call(metrics.PersistenceCreateTasksScope, op, getCustomMetricTags(request)...)
	return
}

func (c *meteredTaskManager) DeleteTaskList(ctx context.Context, request *persistence.DeleteTaskListRequest) (err error) {
	op := func() error {
		err = c.wrapped.DeleteTaskList(ctx, request)
		c.emptyMetric("TaskManager.DeleteTaskList", request, err, err)
		return err
	}

	err = c.call(metrics.PersistenceDeleteTaskListScope, op, getCustomMetricTags(request)...)
	return
}

func (c *meteredTaskManager) GetName() (s1 string) {
	return c.wrapped.GetName()
}

func (c *meteredTaskManager) GetOrphanTasks(ctx context.Context, request *persistence.GetOrphanTasksRequest) (gp1 *persistence.GetOrphanTasksResponse, err error) {
	op := func() error {
		gp1, err = c.wrapped.GetOrphanTasks(ctx, request)
		c.emptyMetric("TaskManager.GetOrphanTasks", request, gp1, err)
		return err
	}

	err = c.call(metrics.PersistenceGetOrphanTasksScope, op, getCustomMetricTags(request)...)
	return
}

func (c *meteredTaskManager) GetTaskList(ctx context.Context, request *persistence.GetTaskListRequest) (gp1 *persistence.GetTaskListResponse, err error) {
	op := func() error {
		gp1, err = c.wrapped.GetTaskList(ctx, request)
		c.emptyMetric("TaskManager.GetTaskList", request, gp1, err)
		return err
	}

	err = c.call(metrics.PersistenceGetTaskListScope, op, getCustomMetricTags(request)...)
	return
}

func (c *meteredTaskManager) GetTaskListSize(ctx context.Context, request *persistence.GetTaskListSizeRequest) (gp1 *persistence.GetTaskListSizeResponse, err error) {
	op := func() error {
		gp1, err = c.wrapped.GetTaskListSize(ctx, request)
		c.emptyMetric("TaskManager.GetTaskListSize", request, gp1, err)
		return err
	}

	err = c.call(metrics.PersistenceGetTaskListSizeScope, op, getCustomMetricTags(request)...)
	return
}

func (c *meteredTaskManager) GetTasks(ctx context.Context, request *persistence.GetTasksRequest) (gp1 *persistence.GetTasksResponse, err error) {
	op := func() error {
		gp1, err = c.wrapped.GetTasks(ctx, request)
		c.emptyMetric("TaskManager.GetTasks", request, gp1, err)
		return err
	}

	err = c.call(metrics.PersistenceGetTasksScope, op, getCustomMetricTags(request)...)
	return
}

func (c *meteredTaskManager) LeaseTaskList(ctx context.Context, request *persistence.LeaseTaskListRequest) (lp1 *persistence.LeaseTaskListResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.LeaseTaskList(ctx, request)
		c.emptyMetric("TaskManager.LeaseTaskList", request, lp1, err)
		return err
	}

	err = c.call(metrics.PersistenceLeaseTaskListScope, op, getCustomMetricTags(request)...)
	return
}

func (c *meteredTaskManager) ListTaskList(ctx context.Context, request *persistence.ListTaskListRequest) (lp1 *persistence.ListTaskListResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.ListTaskList(ctx, request)
		c.emptyMetric("TaskManager.ListTaskList", request, lp1, err)
		return err
	}

	err = c.call(metrics.PersistenceListTaskListScope, op, getCustomMetricTags(request)...)
	return
}

func (c *meteredTaskManager) UpdateTaskList(ctx context.Context, request *persistence.UpdateTaskListRequest) (up1 *persistence.UpdateTaskListResponse, err error) {
	op := func() error {
		up1, err = c.wrapped.UpdateTaskList(ctx, request)
		c.emptyMetric("TaskManager.UpdateTaskList", request, up1, err)
		return err
	}

	err = c.call(metrics.PersistenceUpdateTaskListScope, op, getCustomMetricTags(request)...)
	return
}
