package retryable

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

import (
	"context"

	"go.uber.org/yarpc"

	"github.com/uber/cadence/client/sharddistributorexecutor"
	"github.com/uber/cadence/common/backoff"
	"github.com/uber/cadence/common/types"
)

// sharddistributorexecutorClient implements sharddistributorexecutor.Client interface instrumented with retries
type sharddistributorexecutorClient struct {
	client        sharddistributorexecutor.Client
	throttleRetry *backoff.ThrottleRetry
}

// NewShardDistributorExecutorClient creates a new instance of sharddistributorexecutorClient with retry policy
func NewShardDistributorExecutorClient(client sharddistributorexecutor.Client, policy backoff.RetryPolicy, isRetryable backoff.IsRetryable) sharddistributorexecutor.Client {
	return &sharddistributorexecutorClient{
		client: client,
		throttleRetry: backoff.NewThrottleRetry(
			backoff.WithRetryPolicy(policy),
			backoff.WithRetryableError(isRetryable),
		),
	}
}

func (c *sharddistributorexecutorClient) Heartbeat(ctx context.Context, ep1 *types.ExecutorHeartbeatRequest, p1 ...yarpc.CallOption) (ep2 *types.ExecutorHeartbeatResponse, err error) {
	var resp *types.ExecutorHeartbeatResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.Heartbeat(ctx, ep1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}
