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

package hello

import (
	"context"
	"errors"
	"github.com/cloudwego/kitex/pkg/streaming"
	"kitex/v0.5.1/kitex_gen/api"
	"github.com/cloudwego/kitex/client"
	kitex "github.com/cloudwego/kitex/pkg/serviceinfo"
)

func serviceInfo() *kitex.ServiceInfo {
	return helloServiceInfo
}

var helloServiceInfo = NewServiceInfo()

func NewServiceInfo() *kitex.ServiceInfo {
	serviceName := "Hello"
	handlerType := (*api.Hello)(nil)
	methods := map[string]kitex.MethodInfo{
		"echo": kitex.NewMethodInfo(echoHandler, newHelloEchoArgs, newHelloEchoResult, false),
	}
	extra := map[string]interface{}{
		"PackageName": "api",
	}
	svcInfo := &kitex.ServiceInfo{
		ServiceName:     serviceName,
		HandlerType:     handlerType,
		Methods:         methods,
		PayloadCodec:    kitex.Thrift,
		KiteXGenVersion: "v0.1.4",
		Extra:           extra,
	}
	return svcInfo
}

func echoHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	switch s := arg.(type) {
	case *streaming.Args:
		st := s.Stream
		req := new(api.Request)
		if err := st.RecvMsg(req); err != nil {
			return err
		}
		resp, err := handler.(api.Hello).Echo(ctx, req)
		if err != nil {
			return err
		}
		return st.SendMsg(resp)
	case *api.HelloEchoArgs:
		success, err := handler.(api.Hello).Echo(ctx, s.Req)
		if err != nil {
			return err
		}
		realResult := result.(*api.HelloEchoResult)
		realResult.Success = success
		return nil
	default:
		return errors.New("invalid message type for service method handler")
	}
}
func newHelloEchoArgs() interface{} {
	return api.NewHelloEchoArgs()
}

func newHelloEchoResult() interface{} {
	return api.NewHelloEchoResult()
}

type kClient struct {
	c client.Client
}

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

func (p *kClient) Echo(ctx context.Context, req *api.Request) (r *api.Response, err error) {
	var _args api.HelloEchoArgs
	_args.Req = req
	var _result api.HelloEchoResult
	if err = p.c.Call(ctx, "echo", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}
