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

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

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

func (c *matchingClient) AddActivityTask(ctx context.Context, ap1 *types.AddActivityTaskRequest, p1 ...yarpc.CallOption) (ap2 *types.AddActivityTaskResponse, err error) {
	var resp *types.AddActivityTaskResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.AddActivityTask(ctx, ap1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}

func (c *matchingClient) AddDecisionTask(ctx context.Context, ap1 *types.AddDecisionTaskRequest, p1 ...yarpc.CallOption) (ap2 *types.AddDecisionTaskResponse, err error) {
	var resp *types.AddDecisionTaskResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.AddDecisionTask(ctx, ap1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}

func (c *matchingClient) CancelOutstandingPoll(ctx context.Context, cp1 *types.CancelOutstandingPollRequest, p1 ...yarpc.CallOption) (err error) {
	op := func(ctx context.Context) error {
		return c.client.CancelOutstandingPoll(ctx, cp1, p1...)
	}
	return c.throttleRetry.Do(ctx, op)
}

func (c *matchingClient) DescribeTaskList(ctx context.Context, mp1 *types.MatchingDescribeTaskListRequest, p1 ...yarpc.CallOption) (dp1 *types.DescribeTaskListResponse, err error) {
	var resp *types.DescribeTaskListResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.DescribeTaskList(ctx, mp1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}

func (c *matchingClient) GetTaskListsByDomain(ctx context.Context, gp1 *types.GetTaskListsByDomainRequest, p1 ...yarpc.CallOption) (gp2 *types.GetTaskListsByDomainResponse, err error) {
	var resp *types.GetTaskListsByDomainResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.GetTaskListsByDomain(ctx, gp1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}

func (c *matchingClient) ListTaskListPartitions(ctx context.Context, mp1 *types.MatchingListTaskListPartitionsRequest, p1 ...yarpc.CallOption) (lp1 *types.ListTaskListPartitionsResponse, err error) {
	var resp *types.ListTaskListPartitionsResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.ListTaskListPartitions(ctx, mp1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}

func (c *matchingClient) PollForActivityTask(ctx context.Context, mp1 *types.MatchingPollForActivityTaskRequest, p1 ...yarpc.CallOption) (mp2 *types.MatchingPollForActivityTaskResponse, err error) {
	var resp *types.MatchingPollForActivityTaskResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.PollForActivityTask(ctx, mp1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}

func (c *matchingClient) PollForDecisionTask(ctx context.Context, mp1 *types.MatchingPollForDecisionTaskRequest, p1 ...yarpc.CallOption) (mp2 *types.MatchingPollForDecisionTaskResponse, err error) {
	var resp *types.MatchingPollForDecisionTaskResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.PollForDecisionTask(ctx, mp1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}

func (c *matchingClient) QueryWorkflow(ctx context.Context, mp1 *types.MatchingQueryWorkflowRequest, p1 ...yarpc.CallOption) (mp2 *types.MatchingQueryWorkflowResponse, err error) {
	var resp *types.MatchingQueryWorkflowResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.QueryWorkflow(ctx, mp1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}

func (c *matchingClient) RefreshTaskListPartitionConfig(ctx context.Context, mp1 *types.MatchingRefreshTaskListPartitionConfigRequest, p1 ...yarpc.CallOption) (mp2 *types.MatchingRefreshTaskListPartitionConfigResponse, err error) {
	var resp *types.MatchingRefreshTaskListPartitionConfigResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.RefreshTaskListPartitionConfig(ctx, mp1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}

func (c *matchingClient) RespondQueryTaskCompleted(ctx context.Context, mp1 *types.MatchingRespondQueryTaskCompletedRequest, p1 ...yarpc.CallOption) (err error) {
	op := func(ctx context.Context) error {
		return c.client.RespondQueryTaskCompleted(ctx, mp1, p1...)
	}
	return c.throttleRetry.Do(ctx, op)
}

func (c *matchingClient) UpdateTaskListPartitionConfig(ctx context.Context, mp1 *types.MatchingUpdateTaskListPartitionConfigRequest, p1 ...yarpc.CallOption) (mp2 *types.MatchingUpdateTaskListPartitionConfigResponse, err error) {
	var resp *types.MatchingUpdateTaskListPartitionConfigResponse
	op := func(ctx context.Context) error {
		var err error
		resp, err = c.client.UpdateTaskListPartitionConfig(ctx, mp1, p1...)
		return err
	}
	err = c.throttleRetry.Do(ctx, op)
	return resp, err
}
