// Code generated by protoc-gen-triple. DO NOT EDIT.
//
// Source: currencyservice.proto
package hipstershop

import (
	"context"
)

import (
	"dubbo.apache.org/dubbo-go/v3"
	"dubbo.apache.org/dubbo-go/v3/client"
	"dubbo.apache.org/dubbo-go/v3/common"
	"dubbo.apache.org/dubbo-go/v3/common/constant"
	"dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
	"dubbo.apache.org/dubbo-go/v3/server"
)

// This is a compile-time assertion to ensure that this generated file and the Triple package
// are compatible. If you get a compiler error that this constant is not defined, this code was
// generated with a version of Triple newer than the one compiled into your binary. You can fix the
// problem by either regenerating this code with an older version of Triple or updating the Triple
// version compiled into your binary.
const _ = triple_protocol.IsAtLeastVersion0_1_0

const (
	// CurrencyServiceName is the fully-qualified name of the CurrencyService service.
	CurrencyServiceName = "hipstershop.CurrencyService"
)

// These constants are the fully-qualified names of the RPCs defined in this package. They're
// exposed at runtime as procedure and as the final two segments of the HTTP route.
//
// Note that these are different from the fully-qualified method names used by
// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
// period.
const (
	// CurrencyServiceGetSupportedCurrenciesProcedure is the fully-qualified name of the CurrencyService's GetSupportedCurrencies RPC.
	CurrencyServiceGetSupportedCurrenciesProcedure = "/hipstershop.CurrencyService/GetSupportedCurrencies"
	// CurrencyServiceConvertProcedure is the fully-qualified name of the CurrencyService's Convert RPC.
	CurrencyServiceConvertProcedure = "/hipstershop.CurrencyService/Convert"
)

var (
	_ CurrencyService = (*CurrencyServiceImpl)(nil)
)

// CurrencyService is a client for the hipstershop.CurrencyService service.
type CurrencyService interface {
	GetSupportedCurrencies(ctx context.Context, req *Empty, opts ...client.CallOption) (*GetSupportedCurrenciesResponse, error)
	Convert(ctx context.Context, req *CurrencyConversionRequest, opts ...client.CallOption) (*Money, error)
}

// NewCurrencyService constructs a client for the hipstershop.CurrencyService service.
func NewCurrencyService(cli *client.Client, opts ...client.ReferenceOption) (CurrencyService, error) {
	conn, err := cli.DialWithInfo("hipstershop.CurrencyService", &CurrencyService_ClientInfo, opts...)
	if err != nil {
		return nil, err
	}
	return &CurrencyServiceImpl{
		conn: conn,
	}, nil
}

func SetConsumerCurrencyService(srv common.RPCService) {
	dubbo.SetConsumerServiceWithInfo(srv, &CurrencyService_ClientInfo)
}

// CurrencyServiceImpl implements CurrencyService.
type CurrencyServiceImpl struct {
	conn *client.Connection
}

func (c *CurrencyServiceImpl) GetSupportedCurrencies(ctx context.Context, req *Empty, opts ...client.CallOption) (*GetSupportedCurrenciesResponse, error) {
	resp := new(GetSupportedCurrenciesResponse)
	if err := c.conn.CallUnary(ctx, []interface{}{req}, resp, "GetSupportedCurrencies", opts...); err != nil {
		return nil, err
	}
	return resp, nil
}

func (c *CurrencyServiceImpl) Convert(ctx context.Context, req *CurrencyConversionRequest, opts ...client.CallOption) (*Money, error) {
	resp := new(Money)
	if err := c.conn.CallUnary(ctx, []interface{}{req}, resp, "Convert", opts...); err != nil {
		return nil, err
	}
	return resp, nil
}

var CurrencyService_ClientInfo = client.ClientInfo{
	InterfaceName: "hipstershop.CurrencyService",
	MethodNames:   []string{"GetSupportedCurrencies", "Convert"},
	ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) {
		dubboCli := dubboCliRaw.(*CurrencyServiceImpl)
		dubboCli.conn = conn
	},
}

// CurrencyServiceHandler is an implementation of the hipstershop.CurrencyService service.
type CurrencyServiceHandler interface {
	GetSupportedCurrencies(context.Context, *Empty) (*GetSupportedCurrenciesResponse, error)
	Convert(context.Context, *CurrencyConversionRequest) (*Money, error)
}

func RegisterCurrencyServiceHandler(srv *server.Server, hdlr CurrencyServiceHandler, opts ...server.ServiceOption) error {
	return srv.Register(hdlr, &CurrencyService_ServiceInfo, opts...)
}

func SetProviderCurrencyService(srv common.RPCService) {
	dubbo.SetProviderServiceWithInfo(srv, &CurrencyService_ServiceInfo)
}

var CurrencyService_ServiceInfo = server.ServiceInfo{
	InterfaceName: "hipstershop.CurrencyService",
	ServiceType:   (*CurrencyServiceHandler)(nil),
	Methods: []server.MethodInfo{
		{
			Name: "GetSupportedCurrencies",
			Type: constant.CallUnary,
			ReqInitFunc: func() interface{} {
				return new(Empty)
			},
			MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) {
				req := args[0].(*Empty)
				res, err := handler.(CurrencyServiceHandler).GetSupportedCurrencies(ctx, req)
				if err != nil {
					return nil, err
				}
				return triple_protocol.NewResponse(res), nil
			},
		},
		{
			Name: "Convert",
			Type: constant.CallUnary,
			ReqInitFunc: func() interface{} {
				return new(CurrencyConversionRequest)
			},
			MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) {
				req := args[0].(*CurrencyConversionRequest)
				res, err := handler.(CurrencyServiceHandler).Convert(ctx, req)
				if err != nil {
					return nil, err
				}
				return triple_protocol.NewResponse(res), nil
			},
		},
	},
}
