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

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 (
	// OrderName is the fully-qualified name of the Order service.
	OrderName = "org.apache.dubbogo.samples.shop.order.api.Order"
)

// 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 (
	// OrderSubmitOrderProcedure is the fully-qualified name of the Order's SubmitOrder RPC.
	OrderSubmitOrderProcedure = "/org.apache.dubbogo.samples.shop.order.api.Order/SubmitOrder"
)

var (
	_ Order = (*OrderImpl)(nil)
)

// Order is a client for the org.apache.dubbogo.samples.shop.order.api.Order service.
type Order interface {
	SubmitOrder(ctx context.Context, req *OrderReq, opts ...client.CallOption) (*OrderResp, error)
}

// NewOrder constructs a client for the api.Order service.
func NewOrder(cli *client.Client, opts ...client.ReferenceOption) (Order, error) {
	conn, err := cli.DialWithInfo("org.apache.dubbogo.samples.shop.order.api.Order", &Order_ClientInfo, opts...)
	if err != nil {
		return nil, err
	}
	return &OrderImpl{
		conn: conn,
	}, nil
}

func SetConsumerOrder(srv common.RPCService) {
	dubbo.SetConsumerServiceWithInfo(srv, &Order_ClientInfo)
}

// OrderImpl implements Order.
type OrderImpl struct {
	conn *client.Connection
}

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

var Order_ClientInfo = client.ClientInfo{
	InterfaceName: "org.apache.dubbogo.samples.shop.order.api.Order",
	MethodNames:   []string{"SubmitOrder"},
	ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) {
		dubboCli := dubboCliRaw.(*OrderImpl)
		dubboCli.conn = conn
	},
}

// OrderHandler is an implementation of the org.apache.dubbogo.samples.shop.order.api.Order service.
type OrderHandler interface {
	SubmitOrder(context.Context, *OrderReq) (*OrderResp, error)
}

func RegisterOrderHandler(srv *server.Server, hdlr OrderHandler, opts ...server.ServiceOption) error {
	return srv.Register(hdlr, &Order_ServiceInfo, opts...)
}

func SetProviderOrder(srv common.RPCService) {
	dubbo.SetProviderServiceWithInfo(srv, &Order_ServiceInfo)
}

var Order_ServiceInfo = server.ServiceInfo{
	InterfaceName: "org.apache.dubbogo.samples.shop.order.api.Order",
	ServiceType:   (*OrderHandler)(nil),
	Methods: []server.MethodInfo{
		{
			Name: "SubmitOrder",
			Type: constant.CallUnary,
			ReqInitFunc: func() interface{} {
				return new(OrderReq)
			},
			MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) {
				req := args[0].(*OrderReq)
				res, err := handler.(OrderHandler).SubmitOrder(ctx, req)
				if err != nil {
					return nil, err
				}
				return triple_protocol.NewResponse(res), nil
			},
		},
	},
}
