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

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

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

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

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

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

func (c *injectorTaskManager) CompleteTasksLessThan(ctx context.Context, request *persistence.CompleteTasksLessThanRequest) (cp1 *persistence.CompleteTasksLessThanResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		cp1, err = c.wrapped.CompleteTasksLessThan(ctx, request)
	}

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

func (c *injectorTaskManager) CreateTasks(ctx context.Context, request *persistence.CreateTasksRequest) (cp1 *persistence.CreateTasksResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		cp1, err = c.wrapped.CreateTasks(ctx, request)
	}

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

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

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

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

func (c *injectorTaskManager) GetOrphanTasks(ctx context.Context, request *persistence.GetOrphanTasksRequest) (gp1 *persistence.GetOrphanTasksResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		gp1, err = c.wrapped.GetOrphanTasks(ctx, request)
	}

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

func (c *injectorTaskManager) GetTaskList(ctx context.Context, request *persistence.GetTaskListRequest) (gp1 *persistence.GetTaskListResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		gp1, err = c.wrapped.GetTaskList(ctx, request)
	}

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

func (c *injectorTaskManager) GetTaskListSize(ctx context.Context, request *persistence.GetTaskListSizeRequest) (gp1 *persistence.GetTaskListSizeResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		gp1, err = c.wrapped.GetTaskListSize(ctx, request)
	}

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

func (c *injectorTaskManager) GetTasks(ctx context.Context, request *persistence.GetTasksRequest) (gp1 *persistence.GetTasksResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		gp1, err = c.wrapped.GetTasks(ctx, request)
	}

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

func (c *injectorTaskManager) LeaseTaskList(ctx context.Context, request *persistence.LeaseTaskListRequest) (lp1 *persistence.LeaseTaskListResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.LeaseTaskList(ctx, request)
	}

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

func (c *injectorTaskManager) ListTaskList(ctx context.Context, request *persistence.ListTaskListRequest) (lp1 *persistence.ListTaskListResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ListTaskList(ctx, request)
	}

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

func (c *injectorTaskManager) UpdateTaskList(ctx context.Context, request *persistence.UpdateTaskListRequest) (up1 *persistence.UpdateTaskListResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		up1, err = c.wrapped.UpdateTaskList(ctx, request)
	}

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