// Code generated by Kitex v0.9.1. DO NOT EDIT.

package stockservice

import (
	"context"
	"errors"
	stock "github.com/BeroKiTeer/MyGoMall/common/kitex_gen/stock"
	client "github.com/cloudwego/kitex/client"
	kitex "github.com/cloudwego/kitex/pkg/serviceinfo"
	streaming "github.com/cloudwego/kitex/pkg/streaming"
	proto "google.golang.org/protobuf/proto"
)

var errInvalidMessageType = errors.New("invalid message type for service method handler")

var serviceMethods = map[string]kitex.MethodInfo{
	"ReduceItem": kitex.NewMethodInfo(
		reduceItemHandler,
		newReduceItemArgs,
		newReduceItemResult,
		false,
		kitex.WithStreamingMode(kitex.StreamingUnary),
	),
	"CheckItem": kitex.NewMethodInfo(
		checkItemHandler,
		newCheckItemArgs,
		newCheckItemResult,
		false,
		kitex.WithStreamingMode(kitex.StreamingUnary),
	),
	"ReserveItem": kitex.NewMethodInfo(
		reserveItemHandler,
		newReserveItemArgs,
		newReserveItemResult,
		false,
		kitex.WithStreamingMode(kitex.StreamingUnary),
	),
	"RecoverItem": kitex.NewMethodInfo(
		recoverItemHandler,
		newRecoverItemArgs,
		newRecoverItemResult,
		false,
		kitex.WithStreamingMode(kitex.StreamingUnary),
	),
}

var (
	stockServiceServiceInfo                = NewServiceInfo()
	stockServiceServiceInfoForClient       = NewServiceInfoForClient()
	stockServiceServiceInfoForStreamClient = NewServiceInfoForStreamClient()
)

// for server
func serviceInfo() *kitex.ServiceInfo {
	return stockServiceServiceInfo
}

// for client
func serviceInfoForStreamClient() *kitex.ServiceInfo {
	return stockServiceServiceInfoForStreamClient
}

// for stream client
func serviceInfoForClient() *kitex.ServiceInfo {
	return stockServiceServiceInfoForClient
}

// NewServiceInfo creates a new ServiceInfo containing all methods
func NewServiceInfo() *kitex.ServiceInfo {
	return newServiceInfo(false, true, true)
}

// NewServiceInfo creates a new ServiceInfo containing non-streaming methods
func NewServiceInfoForClient() *kitex.ServiceInfo {
	return newServiceInfo(false, false, true)
}
func NewServiceInfoForStreamClient() *kitex.ServiceInfo {
	return newServiceInfo(true, true, false)
}

func newServiceInfo(hasStreaming bool, keepStreamingMethods bool, keepNonStreamingMethods bool) *kitex.ServiceInfo {
	serviceName := "StockService"
	handlerType := (*stock.StockService)(nil)
	methods := map[string]kitex.MethodInfo{}
	for name, m := range serviceMethods {
		if m.IsStreaming() && !keepStreamingMethods {
			continue
		}
		if !m.IsStreaming() && !keepNonStreamingMethods {
			continue
		}
		methods[name] = m
	}
	extra := map[string]interface{}{
		"PackageName": "stock",
	}
	if hasStreaming {
		extra["streaming"] = hasStreaming
	}
	svcInfo := &kitex.ServiceInfo{
		ServiceName:     serviceName,
		HandlerType:     handlerType,
		Methods:         methods,
		PayloadCodec:    kitex.Protobuf,
		KiteXGenVersion: "v0.9.1",
		Extra:           extra,
	}
	return svcInfo
}

func reduceItemHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	switch s := arg.(type) {
	case *streaming.Args:
		st := s.Stream
		req := new(stock.ReduceItemReq)
		if err := st.RecvMsg(req); err != nil {
			return err
		}
		resp, err := handler.(stock.StockService).ReduceItem(ctx, req)
		if err != nil {
			return err
		}
		return st.SendMsg(resp)
	case *ReduceItemArgs:
		success, err := handler.(stock.StockService).ReduceItem(ctx, s.Req)
		if err != nil {
			return err
		}
		realResult := result.(*ReduceItemResult)
		realResult.Success = success
		return nil
	default:
		return errInvalidMessageType
	}
}
func newReduceItemArgs() interface{} {
	return &ReduceItemArgs{}
}

func newReduceItemResult() interface{} {
	return &ReduceItemResult{}
}

type ReduceItemArgs struct {
	Req *stock.ReduceItemReq
}

func (p *ReduceItemArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
	if !p.IsSetReq() {
		p.Req = new(stock.ReduceItemReq)
	}
	return p.Req.FastRead(buf, _type, number)
}

func (p *ReduceItemArgs) FastWrite(buf []byte) (n int) {
	if !p.IsSetReq() {
		return 0
	}
	return p.Req.FastWrite(buf)
}

func (p *ReduceItemArgs) Size() (n int) {
	if !p.IsSetReq() {
		return 0
	}
	return p.Req.Size()
}

func (p *ReduceItemArgs) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetReq() {
		return out, nil
	}
	return proto.Marshal(p.Req)
}

func (p *ReduceItemArgs) Unmarshal(in []byte) error {
	msg := new(stock.ReduceItemReq)
	if err := proto.Unmarshal(in, msg); err != nil {
		return err
	}
	p.Req = msg
	return nil
}

var ReduceItemArgs_Req_DEFAULT *stock.ReduceItemReq

func (p *ReduceItemArgs) GetReq() *stock.ReduceItemReq {
	if !p.IsSetReq() {
		return ReduceItemArgs_Req_DEFAULT
	}
	return p.Req
}

func (p *ReduceItemArgs) IsSetReq() bool {
	return p.Req != nil
}

func (p *ReduceItemArgs) GetFirstArgument() interface{} {
	return p.Req
}

type ReduceItemResult struct {
	Success *stock.ReduceItemResp
}

var ReduceItemResult_Success_DEFAULT *stock.ReduceItemResp

func (p *ReduceItemResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
	if !p.IsSetSuccess() {
		p.Success = new(stock.ReduceItemResp)
	}
	return p.Success.FastRead(buf, _type, number)
}

func (p *ReduceItemResult) FastWrite(buf []byte) (n int) {
	if !p.IsSetSuccess() {
		return 0
	}
	return p.Success.FastWrite(buf)
}

func (p *ReduceItemResult) Size() (n int) {
	if !p.IsSetSuccess() {
		return 0
	}
	return p.Success.Size()
}

func (p *ReduceItemResult) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetSuccess() {
		return out, nil
	}
	return proto.Marshal(p.Success)
}

func (p *ReduceItemResult) Unmarshal(in []byte) error {
	msg := new(stock.ReduceItemResp)
	if err := proto.Unmarshal(in, msg); err != nil {
		return err
	}
	p.Success = msg
	return nil
}

func (p *ReduceItemResult) GetSuccess() *stock.ReduceItemResp {
	if !p.IsSetSuccess() {
		return ReduceItemResult_Success_DEFAULT
	}
	return p.Success
}

func (p *ReduceItemResult) SetSuccess(x interface{}) {
	p.Success = x.(*stock.ReduceItemResp)
}

func (p *ReduceItemResult) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *ReduceItemResult) GetResult() interface{} {
	return p.Success
}

func checkItemHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	switch s := arg.(type) {
	case *streaming.Args:
		st := s.Stream
		req := new(stock.CheckItemReq)
		if err := st.RecvMsg(req); err != nil {
			return err
		}
		resp, err := handler.(stock.StockService).CheckItem(ctx, req)
		if err != nil {
			return err
		}
		return st.SendMsg(resp)
	case *CheckItemArgs:
		success, err := handler.(stock.StockService).CheckItem(ctx, s.Req)
		if err != nil {
			return err
		}
		realResult := result.(*CheckItemResult)
		realResult.Success = success
		return nil
	default:
		return errInvalidMessageType
	}
}
func newCheckItemArgs() interface{} {
	return &CheckItemArgs{}
}

func newCheckItemResult() interface{} {
	return &CheckItemResult{}
}

type CheckItemArgs struct {
	Req *stock.CheckItemReq
}

func (p *CheckItemArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
	if !p.IsSetReq() {
		p.Req = new(stock.CheckItemReq)
	}
	return p.Req.FastRead(buf, _type, number)
}

func (p *CheckItemArgs) FastWrite(buf []byte) (n int) {
	if !p.IsSetReq() {
		return 0
	}
	return p.Req.FastWrite(buf)
}

func (p *CheckItemArgs) Size() (n int) {
	if !p.IsSetReq() {
		return 0
	}
	return p.Req.Size()
}

func (p *CheckItemArgs) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetReq() {
		return out, nil
	}
	return proto.Marshal(p.Req)
}

func (p *CheckItemArgs) Unmarshal(in []byte) error {
	msg := new(stock.CheckItemReq)
	if err := proto.Unmarshal(in, msg); err != nil {
		return err
	}
	p.Req = msg
	return nil
}

var CheckItemArgs_Req_DEFAULT *stock.CheckItemReq

func (p *CheckItemArgs) GetReq() *stock.CheckItemReq {
	if !p.IsSetReq() {
		return CheckItemArgs_Req_DEFAULT
	}
	return p.Req
}

func (p *CheckItemArgs) IsSetReq() bool {
	return p.Req != nil
}

func (p *CheckItemArgs) GetFirstArgument() interface{} {
	return p.Req
}

type CheckItemResult struct {
	Success *stock.CheckItemResp
}

var CheckItemResult_Success_DEFAULT *stock.CheckItemResp

func (p *CheckItemResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
	if !p.IsSetSuccess() {
		p.Success = new(stock.CheckItemResp)
	}
	return p.Success.FastRead(buf, _type, number)
}

func (p *CheckItemResult) FastWrite(buf []byte) (n int) {
	if !p.IsSetSuccess() {
		return 0
	}
	return p.Success.FastWrite(buf)
}

func (p *CheckItemResult) Size() (n int) {
	if !p.IsSetSuccess() {
		return 0
	}
	return p.Success.Size()
}

func (p *CheckItemResult) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetSuccess() {
		return out, nil
	}
	return proto.Marshal(p.Success)
}

func (p *CheckItemResult) Unmarshal(in []byte) error {
	msg := new(stock.CheckItemResp)
	if err := proto.Unmarshal(in, msg); err != nil {
		return err
	}
	p.Success = msg
	return nil
}

func (p *CheckItemResult) GetSuccess() *stock.CheckItemResp {
	if !p.IsSetSuccess() {
		return CheckItemResult_Success_DEFAULT
	}
	return p.Success
}

func (p *CheckItemResult) SetSuccess(x interface{}) {
	p.Success = x.(*stock.CheckItemResp)
}

func (p *CheckItemResult) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *CheckItemResult) GetResult() interface{} {
	return p.Success
}

func reserveItemHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	switch s := arg.(type) {
	case *streaming.Args:
		st := s.Stream
		req := new(stock.ReserveItemReq)
		if err := st.RecvMsg(req); err != nil {
			return err
		}
		resp, err := handler.(stock.StockService).ReserveItem(ctx, req)
		if err != nil {
			return err
		}
		return st.SendMsg(resp)
	case *ReserveItemArgs:
		success, err := handler.(stock.StockService).ReserveItem(ctx, s.Req)
		if err != nil {
			return err
		}
		realResult := result.(*ReserveItemResult)
		realResult.Success = success
		return nil
	default:
		return errInvalidMessageType
	}
}
func newReserveItemArgs() interface{} {
	return &ReserveItemArgs{}
}

func newReserveItemResult() interface{} {
	return &ReserveItemResult{}
}

type ReserveItemArgs struct {
	Req *stock.ReserveItemReq
}

func (p *ReserveItemArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
	if !p.IsSetReq() {
		p.Req = new(stock.ReserveItemReq)
	}
	return p.Req.FastRead(buf, _type, number)
}

func (p *ReserveItemArgs) FastWrite(buf []byte) (n int) {
	if !p.IsSetReq() {
		return 0
	}
	return p.Req.FastWrite(buf)
}

func (p *ReserveItemArgs) Size() (n int) {
	if !p.IsSetReq() {
		return 0
	}
	return p.Req.Size()
}

func (p *ReserveItemArgs) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetReq() {
		return out, nil
	}
	return proto.Marshal(p.Req)
}

func (p *ReserveItemArgs) Unmarshal(in []byte) error {
	msg := new(stock.ReserveItemReq)
	if err := proto.Unmarshal(in, msg); err != nil {
		return err
	}
	p.Req = msg
	return nil
}

var ReserveItemArgs_Req_DEFAULT *stock.ReserveItemReq

func (p *ReserveItemArgs) GetReq() *stock.ReserveItemReq {
	if !p.IsSetReq() {
		return ReserveItemArgs_Req_DEFAULT
	}
	return p.Req
}

func (p *ReserveItemArgs) IsSetReq() bool {
	return p.Req != nil
}

func (p *ReserveItemArgs) GetFirstArgument() interface{} {
	return p.Req
}

type ReserveItemResult struct {
	Success *stock.ReserveItemResp
}

var ReserveItemResult_Success_DEFAULT *stock.ReserveItemResp

func (p *ReserveItemResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
	if !p.IsSetSuccess() {
		p.Success = new(stock.ReserveItemResp)
	}
	return p.Success.FastRead(buf, _type, number)
}

func (p *ReserveItemResult) FastWrite(buf []byte) (n int) {
	if !p.IsSetSuccess() {
		return 0
	}
	return p.Success.FastWrite(buf)
}

func (p *ReserveItemResult) Size() (n int) {
	if !p.IsSetSuccess() {
		return 0
	}
	return p.Success.Size()
}

func (p *ReserveItemResult) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetSuccess() {
		return out, nil
	}
	return proto.Marshal(p.Success)
}

func (p *ReserveItemResult) Unmarshal(in []byte) error {
	msg := new(stock.ReserveItemResp)
	if err := proto.Unmarshal(in, msg); err != nil {
		return err
	}
	p.Success = msg
	return nil
}

func (p *ReserveItemResult) GetSuccess() *stock.ReserveItemResp {
	if !p.IsSetSuccess() {
		return ReserveItemResult_Success_DEFAULT
	}
	return p.Success
}

func (p *ReserveItemResult) SetSuccess(x interface{}) {
	p.Success = x.(*stock.ReserveItemResp)
}

func (p *ReserveItemResult) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *ReserveItemResult) GetResult() interface{} {
	return p.Success
}

func recoverItemHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	switch s := arg.(type) {
	case *streaming.Args:
		st := s.Stream
		req := new(stock.RecoverItemReq)
		if err := st.RecvMsg(req); err != nil {
			return err
		}
		resp, err := handler.(stock.StockService).RecoverItem(ctx, req)
		if err != nil {
			return err
		}
		return st.SendMsg(resp)
	case *RecoverItemArgs:
		success, err := handler.(stock.StockService).RecoverItem(ctx, s.Req)
		if err != nil {
			return err
		}
		realResult := result.(*RecoverItemResult)
		realResult.Success = success
		return nil
	default:
		return errInvalidMessageType
	}
}
func newRecoverItemArgs() interface{} {
	return &RecoverItemArgs{}
}

func newRecoverItemResult() interface{} {
	return &RecoverItemResult{}
}

type RecoverItemArgs struct {
	Req *stock.RecoverItemReq
}

func (p *RecoverItemArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
	if !p.IsSetReq() {
		p.Req = new(stock.RecoverItemReq)
	}
	return p.Req.FastRead(buf, _type, number)
}

func (p *RecoverItemArgs) FastWrite(buf []byte) (n int) {
	if !p.IsSetReq() {
		return 0
	}
	return p.Req.FastWrite(buf)
}

func (p *RecoverItemArgs) Size() (n int) {
	if !p.IsSetReq() {
		return 0
	}
	return p.Req.Size()
}

func (p *RecoverItemArgs) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetReq() {
		return out, nil
	}
	return proto.Marshal(p.Req)
}

func (p *RecoverItemArgs) Unmarshal(in []byte) error {
	msg := new(stock.RecoverItemReq)
	if err := proto.Unmarshal(in, msg); err != nil {
		return err
	}
	p.Req = msg
	return nil
}

var RecoverItemArgs_Req_DEFAULT *stock.RecoverItemReq

func (p *RecoverItemArgs) GetReq() *stock.RecoverItemReq {
	if !p.IsSetReq() {
		return RecoverItemArgs_Req_DEFAULT
	}
	return p.Req
}

func (p *RecoverItemArgs) IsSetReq() bool {
	return p.Req != nil
}

func (p *RecoverItemArgs) GetFirstArgument() interface{} {
	return p.Req
}

type RecoverItemResult struct {
	Success *stock.RecoverItemResp
}

var RecoverItemResult_Success_DEFAULT *stock.RecoverItemResp

func (p *RecoverItemResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
	if !p.IsSetSuccess() {
		p.Success = new(stock.RecoverItemResp)
	}
	return p.Success.FastRead(buf, _type, number)
}

func (p *RecoverItemResult) FastWrite(buf []byte) (n int) {
	if !p.IsSetSuccess() {
		return 0
	}
	return p.Success.FastWrite(buf)
}

func (p *RecoverItemResult) Size() (n int) {
	if !p.IsSetSuccess() {
		return 0
	}
	return p.Success.Size()
}

func (p *RecoverItemResult) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetSuccess() {
		return out, nil
	}
	return proto.Marshal(p.Success)
}

func (p *RecoverItemResult) Unmarshal(in []byte) error {
	msg := new(stock.RecoverItemResp)
	if err := proto.Unmarshal(in, msg); err != nil {
		return err
	}
	p.Success = msg
	return nil
}

func (p *RecoverItemResult) GetSuccess() *stock.RecoverItemResp {
	if !p.IsSetSuccess() {
		return RecoverItemResult_Success_DEFAULT
	}
	return p.Success
}

func (p *RecoverItemResult) SetSuccess(x interface{}) {
	p.Success = x.(*stock.RecoverItemResp)
}

func (p *RecoverItemResult) IsSetSuccess() bool {
	return p.Success != nil
}

func (p *RecoverItemResult) GetResult() interface{} {
	return p.Success
}

type kClient struct {
	c client.Client
}

func newServiceClient(c client.Client) *kClient {
	return &kClient{
		c: c,
	}
}

func (p *kClient) ReduceItem(ctx context.Context, Req *stock.ReduceItemReq) (r *stock.ReduceItemResp, err error) {
	var _args ReduceItemArgs
	_args.Req = Req
	var _result ReduceItemResult
	if err = p.c.Call(ctx, "ReduceItem", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}

func (p *kClient) CheckItem(ctx context.Context, Req *stock.CheckItemReq) (r *stock.CheckItemResp, err error) {
	var _args CheckItemArgs
	_args.Req = Req
	var _result CheckItemResult
	if err = p.c.Call(ctx, "CheckItem", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}

func (p *kClient) ReserveItem(ctx context.Context, Req *stock.ReserveItemReq) (r *stock.ReserveItemResp, err error) {
	var _args ReserveItemArgs
	_args.Req = Req
	var _result ReserveItemResult
	if err = p.c.Call(ctx, "ReserveItem", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}

func (p *kClient) RecoverItem(ctx context.Context, Req *stock.RecoverItemReq) (r *stock.RecoverItemResp, err error) {
	var _args RecoverItemArgs
	_args.Req = Req
	var _result RecoverItemResult
	if err = p.c.Call(ctx, "RecoverItem", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}
