package errorinjectors

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

import (
	"context"

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

// injectorVisibilityManager implements persistence.VisibilityManager interface instrumented with error injection.
type injectorVisibilityManager struct {
	wrapped   persistence.VisibilityManager
	errorRate float64
	logger    log.Logger
}

// NewVisibilityManager creates a new instance of VisibilityManager with error injection.
func NewVisibilityManager(
	wrapped persistence.VisibilityManager,
	errorRate float64,
	logger log.Logger,
) persistence.VisibilityManager {
	return &injectorVisibilityManager{
		wrapped:   wrapped,
		errorRate: errorRate,
		logger:    logger,
	}
}

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

func (c *injectorVisibilityManager) CountWorkflowExecutions(ctx context.Context, request *persistence.CountWorkflowExecutionsRequest) (cp1 *persistence.CountWorkflowExecutionsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		cp1, err = c.wrapped.CountWorkflowExecutions(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.CountWorkflowExecutions", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) DeleteUninitializedWorkflowExecution(ctx context.Context, request *persistence.VisibilityDeleteWorkflowExecutionRequest) (err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		err = c.wrapped.DeleteUninitializedWorkflowExecution(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.DeleteUninitializedWorkflowExecution", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) DeleteWorkflowExecution(ctx context.Context, request *persistence.VisibilityDeleteWorkflowExecutionRequest) (err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		err = c.wrapped.DeleteWorkflowExecution(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.DeleteWorkflowExecution", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) GetClosedWorkflowExecution(ctx context.Context, request *persistence.GetClosedWorkflowExecutionRequest) (gp1 *persistence.GetClosedWorkflowExecutionResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		gp1, err = c.wrapped.GetClosedWorkflowExecution(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.GetClosedWorkflowExecution", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

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

func (c *injectorVisibilityManager) ListClosedWorkflowExecutions(ctx context.Context, request *persistence.ListWorkflowExecutionsRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ListClosedWorkflowExecutions(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.ListClosedWorkflowExecutions", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) ListClosedWorkflowExecutionsByStatus(ctx context.Context, request *persistence.ListClosedWorkflowExecutionsByStatusRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ListClosedWorkflowExecutionsByStatus(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.ListClosedWorkflowExecutionsByStatus", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) ListClosedWorkflowExecutionsByType(ctx context.Context, request *persistence.ListWorkflowExecutionsByTypeRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ListClosedWorkflowExecutionsByType(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.ListClosedWorkflowExecutionsByType", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) ListClosedWorkflowExecutionsByWorkflowID(ctx context.Context, request *persistence.ListWorkflowExecutionsByWorkflowIDRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ListClosedWorkflowExecutionsByWorkflowID(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.ListClosedWorkflowExecutionsByWorkflowID", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) ListOpenWorkflowExecutions(ctx context.Context, request *persistence.ListWorkflowExecutionsRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ListOpenWorkflowExecutions(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.ListOpenWorkflowExecutions", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) ListOpenWorkflowExecutionsByType(ctx context.Context, request *persistence.ListWorkflowExecutionsByTypeRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ListOpenWorkflowExecutionsByType(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.ListOpenWorkflowExecutionsByType", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) ListOpenWorkflowExecutionsByWorkflowID(ctx context.Context, request *persistence.ListWorkflowExecutionsByWorkflowIDRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ListOpenWorkflowExecutionsByWorkflowID(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.ListOpenWorkflowExecutionsByWorkflowID", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) ListWorkflowExecutions(ctx context.Context, request *persistence.ListWorkflowExecutionsByQueryRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ListWorkflowExecutions(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.ListWorkflowExecutions", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) RecordWorkflowExecutionClosed(ctx context.Context, request *persistence.RecordWorkflowExecutionClosedRequest) (err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		err = c.wrapped.RecordWorkflowExecutionClosed(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.RecordWorkflowExecutionClosed", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) RecordWorkflowExecutionStarted(ctx context.Context, request *persistence.RecordWorkflowExecutionStartedRequest) (err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		err = c.wrapped.RecordWorkflowExecutionStarted(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.RecordWorkflowExecutionStarted", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) RecordWorkflowExecutionUninitialized(ctx context.Context, request *persistence.RecordWorkflowExecutionUninitializedRequest) (err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		err = c.wrapped.RecordWorkflowExecutionUninitialized(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.RecordWorkflowExecutionUninitialized", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) ScanWorkflowExecutions(ctx context.Context, request *persistence.ListWorkflowExecutionsByQueryRequest) (lp1 *persistence.ListWorkflowExecutionsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ScanWorkflowExecutions(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.ScanWorkflowExecutions", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}

func (c *injectorVisibilityManager) UpsertWorkflowExecution(ctx context.Context, request *persistence.UpsertWorkflowExecutionRequest) (err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		err = c.wrapped.UpsertWorkflowExecution(ctx, request)
	}

	if fakeErr != nil {
		logErr(c.logger, "VisibilityManager.UpsertWorkflowExecution", fakeErr, forwardCall, err)
		err = fakeErr
		return
	}
	return
}
