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

// meteredVisibilityManager implements persistence.VisibilityManager interface instrumented with rate limiter.
type meteredVisibilityManager struct {
	base
	wrapped persistence.VisibilityManager
}

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

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

func (c *meteredVisibilityManager) CountWorkflowExecutions(ctx context.Context, request *persistence.CountWorkflowExecutionsRequest) (cp1 *persistence.CountWorkflowExecutionsResponse, err error) {
	op := func() error {
		cp1, err = c.wrapped.CountWorkflowExecutions(ctx, request)
		c.emptyMetric("VisibilityManager.CountWorkflowExecutions", request, cp1, err)
		return err
	}

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

func (c *meteredVisibilityManager) DeleteUninitializedWorkflowExecution(ctx context.Context, request *persistence.VisibilityDeleteWorkflowExecutionRequest) (err error) {
	op := func() error {
		err = c.wrapped.DeleteUninitializedWorkflowExecution(ctx, request)
		c.emptyMetric("VisibilityManager.DeleteUninitializedWorkflowExecution", request, err, err)
		return err
	}

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

func (c *meteredVisibilityManager) DeleteWorkflowExecution(ctx context.Context, request *persistence.VisibilityDeleteWorkflowExecutionRequest) (err error) {
	op := func() error {
		err = c.wrapped.DeleteWorkflowExecution(ctx, request)
		c.emptyMetric("VisibilityManager.DeleteWorkflowExecution", request, err, err)
		return err
	}

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

func (c *meteredVisibilityManager) GetClosedWorkflowExecution(ctx context.Context, request *persistence.GetClosedWorkflowExecutionRequest) (gp1 *persistence.GetClosedWorkflowExecutionResponse, err error) {
	op := func() error {
		gp1, err = c.wrapped.GetClosedWorkflowExecution(ctx, request)
		c.emptyMetric("VisibilityManager.GetClosedWorkflowExecution", request, gp1, err)
		return err
	}

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

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

func (c *meteredVisibilityManager) ListClosedWorkflowExecutions(ctx context.Context, request *persistence.ListWorkflowExecutionsRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.ListClosedWorkflowExecutions(ctx, request)
		c.emptyMetric("VisibilityManager.ListClosedWorkflowExecutions", request, lp1, err)
		return err
	}

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

func (c *meteredVisibilityManager) ListClosedWorkflowExecutionsByStatus(ctx context.Context, request *persistence.ListClosedWorkflowExecutionsByStatusRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.ListClosedWorkflowExecutionsByStatus(ctx, request)
		c.emptyMetric("VisibilityManager.ListClosedWorkflowExecutionsByStatus", request, lp1, err)
		return err
	}

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

func (c *meteredVisibilityManager) ListClosedWorkflowExecutionsByType(ctx context.Context, request *persistence.ListWorkflowExecutionsByTypeRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.ListClosedWorkflowExecutionsByType(ctx, request)
		c.emptyMetric("VisibilityManager.ListClosedWorkflowExecutionsByType", request, lp1, err)
		return err
	}

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

func (c *meteredVisibilityManager) ListClosedWorkflowExecutionsByWorkflowID(ctx context.Context, request *persistence.ListWorkflowExecutionsByWorkflowIDRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.ListClosedWorkflowExecutionsByWorkflowID(ctx, request)
		c.emptyMetric("VisibilityManager.ListClosedWorkflowExecutionsByWorkflowID", request, lp1, err)
		return err
	}

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

func (c *meteredVisibilityManager) ListOpenWorkflowExecutions(ctx context.Context, request *persistence.ListWorkflowExecutionsRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.ListOpenWorkflowExecutions(ctx, request)
		c.emptyMetric("VisibilityManager.ListOpenWorkflowExecutions", request, lp1, err)
		return err
	}

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

func (c *meteredVisibilityManager) ListOpenWorkflowExecutionsByType(ctx context.Context, request *persistence.ListWorkflowExecutionsByTypeRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.ListOpenWorkflowExecutionsByType(ctx, request)
		c.emptyMetric("VisibilityManager.ListOpenWorkflowExecutionsByType", request, lp1, err)
		return err
	}

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

func (c *meteredVisibilityManager) ListOpenWorkflowExecutionsByWorkflowID(ctx context.Context, request *persistence.ListWorkflowExecutionsByWorkflowIDRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.ListOpenWorkflowExecutionsByWorkflowID(ctx, request)
		c.emptyMetric("VisibilityManager.ListOpenWorkflowExecutionsByWorkflowID", request, lp1, err)
		return err
	}

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

func (c *meteredVisibilityManager) ListWorkflowExecutions(ctx context.Context, request *persistence.ListWorkflowExecutionsByQueryRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.ListWorkflowExecutions(ctx, request)
		c.emptyMetric("VisibilityManager.ListWorkflowExecutions", request, lp1, err)
		return err
	}

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

func (c *meteredVisibilityManager) RecordWorkflowExecutionClosed(ctx context.Context, request *persistence.RecordWorkflowExecutionClosedRequest) (err error) {
	op := func() error {
		err = c.wrapped.RecordWorkflowExecutionClosed(ctx, request)
		c.emptyMetric("VisibilityManager.RecordWorkflowExecutionClosed", request, err, err)
		return err
	}

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

func (c *meteredVisibilityManager) RecordWorkflowExecutionStarted(ctx context.Context, request *persistence.RecordWorkflowExecutionStartedRequest) (err error) {
	op := func() error {
		err = c.wrapped.RecordWorkflowExecutionStarted(ctx, request)
		c.emptyMetric("VisibilityManager.RecordWorkflowExecutionStarted", request, err, err)
		return err
	}

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

func (c *meteredVisibilityManager) RecordWorkflowExecutionUninitialized(ctx context.Context, request *persistence.RecordWorkflowExecutionUninitializedRequest) (err error) {
	op := func() error {
		err = c.wrapped.RecordWorkflowExecutionUninitialized(ctx, request)
		c.emptyMetric("VisibilityManager.RecordWorkflowExecutionUninitialized", request, err, err)
		return err
	}

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

func (c *meteredVisibilityManager) ScanWorkflowExecutions(ctx context.Context, request *persistence.ListWorkflowExecutionsByQueryRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	op := func() error {
		lp1, err = c.wrapped.ScanWorkflowExecutions(ctx, request)
		c.emptyMetric("VisibilityManager.ScanWorkflowExecutions", request, lp1, err)
		return err
	}

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

func (c *meteredVisibilityManager) UpsertWorkflowExecution(ctx context.Context, request *persistence.UpsertWorkflowExecutionRequest) (err error) {
	op := func() error {
		err = c.wrapped.UpsertWorkflowExecution(ctx, request)
		c.emptyMetric("VisibilityManager.UpsertWorkflowExecution", request, err, err)
		return err
	}

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