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

package messageservice

import (
	rpc "common/kitex_gen/douyin/rpc"
	"context"
	client "github.com/cloudwego/kitex/client"
	kitex "github.com/cloudwego/kitex/pkg/serviceinfo"
)

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

var messageServiceServiceInfo = NewServiceInfo()

func NewServiceInfo() *kitex.ServiceInfo {
	serviceName := "MessageService"
	handlerType := (*rpc.MessageService)(nil)
	methods := map[string]kitex.MethodInfo{
		"Chat":           kitex.NewMethodInfo(chatHandler, newMessageServiceChatArgs, newMessageServiceChatResult, false),
		"Message":        kitex.NewMethodInfo(messageHandler, newMessageServiceMessageArgs, newMessageServiceMessageResult, false),
		"LatestMessages": kitex.NewMethodInfo(latestMessagesHandler, newMessageServiceLatestMessagesArgs, newMessageServiceLatestMessagesResult, false),
	}
	extra := map[string]interface{}{
		"PackageName": "rpc",
	}
	svcInfo := &kitex.ServiceInfo{
		ServiceName:     serviceName,
		HandlerType:     handlerType,
		Methods:         methods,
		PayloadCodec:    kitex.Thrift,
		KiteXGenVersion: "v0.4.4",
		Extra:           extra,
	}
	return svcInfo
}

func chatHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	realArg := arg.(*rpc.MessageServiceChatArgs)
	realResult := result.(*rpc.MessageServiceChatResult)
	success, err := handler.(rpc.MessageService).Chat(ctx, realArg.Req)
	if err != nil {
		return err
	}
	realResult.Success = success
	return nil
}
func newMessageServiceChatArgs() interface{} {
	return rpc.NewMessageServiceChatArgs()
}

func newMessageServiceChatResult() interface{} {
	return rpc.NewMessageServiceChatResult()
}

func messageHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	realArg := arg.(*rpc.MessageServiceMessageArgs)
	realResult := result.(*rpc.MessageServiceMessageResult)
	success, err := handler.(rpc.MessageService).Message(ctx, realArg.Req)
	if err != nil {
		return err
	}
	realResult.Success = success
	return nil
}
func newMessageServiceMessageArgs() interface{} {
	return rpc.NewMessageServiceMessageArgs()
}

func newMessageServiceMessageResult() interface{} {
	return rpc.NewMessageServiceMessageResult()
}

func latestMessagesHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	realArg := arg.(*rpc.MessageServiceLatestMessagesArgs)
	realResult := result.(*rpc.MessageServiceLatestMessagesResult)
	success, err := handler.(rpc.MessageService).LatestMessages(ctx, realArg.Req)
	if err != nil {
		return err
	}
	realResult.Success = success
	return nil
}
func newMessageServiceLatestMessagesArgs() interface{} {
	return rpc.NewMessageServiceLatestMessagesArgs()
}

func newMessageServiceLatestMessagesResult() interface{} {
	return rpc.NewMessageServiceLatestMessagesResult()
}

type kClient struct {
	c client.Client
}

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

func (p *kClient) Chat(ctx context.Context, req *rpc.DouyinMessageChatRequest) (r *rpc.DouyinMessageChatResponse, err error) {
	var _args rpc.MessageServiceChatArgs
	_args.Req = req
	var _result rpc.MessageServiceChatResult
	if err = p.c.Call(ctx, "Chat", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}

func (p *kClient) Message(ctx context.Context, req *rpc.DouyinMessageActionRequest) (r *rpc.DouyinMessageActionResponse, err error) {
	var _args rpc.MessageServiceMessageArgs
	_args.Req = req
	var _result rpc.MessageServiceMessageResult
	if err = p.c.Call(ctx, "Message", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}

func (p *kClient) LatestMessages(ctx context.Context, req *rpc.LatestMessageRequest) (r *rpc.LatestMessageResponse, err error) {
	var _args rpc.MessageServiceLatestMessagesArgs
	_args.Req = req
	var _result rpc.MessageServiceLatestMessagesResult
	if err = p.c.Call(ctx, "LatestMessages", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}
