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

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

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

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

func (c *injectorDomainManager) CreateDomain(ctx context.Context, request *persistence.CreateDomainRequest) (cp1 *persistence.CreateDomainResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		cp1, err = c.wrapped.CreateDomain(ctx, request)
	}

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

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

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

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

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

func (c *injectorDomainManager) GetDomain(ctx context.Context, request *persistence.GetDomainRequest) (gp1 *persistence.GetDomainResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		gp1, err = c.wrapped.GetDomain(ctx, request)
	}

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

func (c *injectorDomainManager) GetMetadata(ctx context.Context) (gp1 *persistence.GetMetadataResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		gp1, err = c.wrapped.GetMetadata(ctx)
	}

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

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

func (c *injectorDomainManager) ListDomains(ctx context.Context, request *persistence.ListDomainsRequest) (lp1 *persistence.ListDomainsResponse, err error) {
	fakeErr := generateFakeError(c.errorRate)
	var forwardCall bool
	if forwardCall = shouldForwardCallToPersistence(fakeErr); forwardCall {
		lp1, err = c.wrapped.ListDomains(ctx, request)
	}

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

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

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