// Code generated by protoc-gen-triple. DO NOT EDIT.
//
// Source: detail_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 (
	// DetailName is the fully-qualified name of the Detail service.
	DetailName = "org.apache.dubbogo.samples.shop.detail.api.Detail"
)

// 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 (
	// DetailGetItemProcedure is the fully-qualified name of the Detail's GetItem RPC.
	DetailGetItemProcedure = "/org.apache.dubbogo.samples.shop.detail.api.Detail/GetItem"
	// DetailDeductStockProcedure is the fully-qualified name of the Detail's DeductStock RPC.
	DetailDeductStockProcedure = "/org.apache.dubbogo.samples.shop.detail.api.Detail/DeductStock"
)

var (
	_ Detail = (*DetailImpl)(nil)
)

// Detail is a client for the org.apache.dubbogo.samples.shop.detail.api.Detail service.
type Detail interface {
	GetItem(ctx context.Context, req *GetItemReq, opts ...client.CallOption) (*Item, error)
	DeductStock(ctx context.Context, req *DeductStockReq, opts ...client.CallOption) (*DeductStockResp, error)
}

// NewDetail constructs a client for the api.Detail service.
func NewDetail(cli *client.Client, opts ...client.ReferenceOption) (Detail, error) {
	conn, err := cli.DialWithInfo("org.apache.dubbogo.samples.shop.detail.api.Detail", &Detail_ClientInfo, opts...)
	if err != nil {
		return nil, err
	}
	return &DetailImpl{
		conn: conn,
	}, nil
}

func SetConsumerDetail(srv common.RPCService) {
	dubbo.SetConsumerServiceWithInfo(srv, &Detail_ClientInfo)
}

// DetailImpl implements Detail.
type DetailImpl struct {
	conn *client.Connection
}

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

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

var Detail_ClientInfo = client.ClientInfo{
	InterfaceName: "org.apache.dubbogo.samples.shop.detail.api.Detail",
	MethodNames:   []string{"GetItem", "DeductStock"},
	ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) {
		dubboCli := dubboCliRaw.(*DetailImpl)
		dubboCli.conn = conn
	},
}

// DetailHandler is an implementation of the org.apache.dubbogo.samples.shop.detail.api.Detail service.
type DetailHandler interface {
	GetItem(context.Context, *GetItemReq) (*Item, error)
	DeductStock(context.Context, *DeductStockReq) (*DeductStockResp, error)
}

func RegisterDetailHandler(srv *server.Server, hdlr DetailHandler, opts ...server.ServiceOption) error {
	return srv.Register(hdlr, &Detail_ServiceInfo, opts...)
}

func SetProviderDetail(srv common.RPCService) {
	dubbo.SetProviderServiceWithInfo(srv, &Detail_ServiceInfo)
}

var Detail_ServiceInfo = server.ServiceInfo{
	InterfaceName: "org.apache.dubbogo.samples.shop.detail.api.Detail",
	ServiceType:   (*DetailHandler)(nil),
	Methods: []server.MethodInfo{
		{
			Name: "GetItem",
			Type: constant.CallUnary,
			ReqInitFunc: func() interface{} {
				return new(GetItemReq)
			},
			MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) {
				req := args[0].(*GetItemReq)
				res, err := handler.(DetailHandler).GetItem(ctx, req)
				if err != nil {
					return nil, err
				}
				return triple_protocol.NewResponse(res), nil
			},
		},
		{
			Name: "DeductStock",
			Type: constant.CallUnary,
			ReqInitFunc: func() interface{} {
				return new(DeductStockReq)
			},
			MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) {
				req := args[0].(*DeductStockReq)
				res, err := handler.(DetailHandler).DeductStock(ctx, req)
				if err != nil {
					return nil, err
				}
				return triple_protocol.NewResponse(res), nil
			},
		},
	},
}
