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/sharddistributor"
	"github.com/uber/cadence/common/backoff"
	"github.com/uber/cadence/common/types"
)

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

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

func (c *sharddistributorClient) GetShardOwner(ctx context.Context, gp1 *types.GetShardOwnerRequest, p1 ...yarpc.CallOption) (gp2 *types.GetShardOwnerResponse, err error) {
	var resp *types.GetShardOwnerResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.GetShardOwner(ctx, gp1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}
