// Code generated by thriftrw-plugin-yarpc
// @generated

package metaclient

import (
	context "context"
	reflect "reflect"

	wire "go.uber.org/thriftrw/wire"
	yarpc "go.uber.org/yarpc"
	transport "go.uber.org/yarpc/api/transport"
	thrift "go.uber.org/yarpc/encoding/thrift"

	health "github.com/uber/cadence/.gen/go/health"
)

// Interface is a client for the Meta service.
type Interface interface {
	Health(
		ctx context.Context,
		opts ...yarpc.CallOption,
	) (*health.HealthStatus, error)
}

// New builds a new client for the Meta service.
//
//	client := metaclient.New(dispatcher.ClientConfig("meta"))
func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface {
	return client{
		c: thrift.New(thrift.Config{
			Service:      "Meta",
			ClientConfig: c,
		}, opts...),
		nwc: thrift.NewNoWire(thrift.Config{
			Service:      "Meta",
			ClientConfig: c,
		}, opts...),
	}
}

func init() {
	yarpc.RegisterClientBuilder(
		func(c transport.ClientConfig, f reflect.StructField) Interface {
			return New(c, thrift.ClientBuilderOptions(c, f)...)
		},
	)
}

type client struct {
	c   thrift.Client
	nwc thrift.NoWireClient
}

func (c client) Health(
	ctx context.Context,
	opts ...yarpc.CallOption,
) (success *health.HealthStatus, err error) {

	var result health.Meta_Health_Result
	args := health.Meta_Health_Helper.Args()

	if c.nwc != nil && c.nwc.Enabled() {
		if err = c.nwc.Call(ctx, args, &result, opts...); err != nil {
			return
		}
	} else {
		var body wire.Value
		if body, err = c.c.Call(ctx, args, opts...); err != nil {
			return
		}

		if err = result.FromWire(body); err != nil {
			return
		}
	}

	success, err = health.Meta_Health_Helper.UnwrapResponse(&result)
	return
}
