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

package messageservice

import (
	"context"
	message "github.com/PICOF/simple-tiktok/kitex_gen/message"
	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 := (*message.MessageService)(nil)
	methods := map[string]kitex.MethodInfo{
		"SendMessage":   kitex.NewMethodInfo(sendMessageHandler, newMessageServiceSendMessageArgs, newMessageServiceSendMessageResult, false),
		"GetChatRecord": kitex.NewMethodInfo(getChatRecordHandler, newMessageServiceGetChatRecordArgs, newMessageServiceGetChatRecordResult, false),
	}
	extra := map[string]interface{}{
		"PackageName": "message",
	}
	svcInfo := &kitex.ServiceInfo{
		ServiceName:     serviceName,
		HandlerType:     handlerType,
		Methods:         methods,
		PayloadCodec:    kitex.Thrift,
		KiteXGenVersion: "v0.4.4",
		Extra:           extra,
	}
	return svcInfo
}

func sendMessageHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	realArg := arg.(*message.MessageServiceSendMessageArgs)
	realResult := result.(*message.MessageServiceSendMessageResult)
	success, err := handler.(message.MessageService).SendMessage(ctx, realArg.Request)
	if err != nil {
		return err
	}
	realResult.Success = success
	return nil
}
func newMessageServiceSendMessageArgs() interface{} {
	return message.NewMessageServiceSendMessageArgs()
}

func newMessageServiceSendMessageResult() interface{} {
	return message.NewMessageServiceSendMessageResult()
}

func getChatRecordHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	realArg := arg.(*message.MessageServiceGetChatRecordArgs)
	realResult := result.(*message.MessageServiceGetChatRecordResult)
	success, err := handler.(message.MessageService).GetChatRecord(ctx, realArg.Request)
	if err != nil {
		return err
	}
	realResult.Success = success
	return nil
}
func newMessageServiceGetChatRecordArgs() interface{} {
	return message.NewMessageServiceGetChatRecordArgs()
}

func newMessageServiceGetChatRecordResult() interface{} {
	return message.NewMessageServiceGetChatRecordResult()
}

type kClient struct {
	c client.Client
}

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

func (p *kClient) SendMessage(ctx context.Context, request *message.MessageRequest) (r *message.MessageResponse, err error) {
	var _args message.MessageServiceSendMessageArgs
	_args.Request = request
	var _result message.MessageServiceSendMessageResult
	if err = p.c.Call(ctx, "SendMessage", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}

func (p *kClient) GetChatRecord(ctx context.Context, request *message.ChatRecordRequest) (r *message.ChatRecordResponse, err error) {
	var _args message.MessageServiceGetChatRecordArgs
	_args.Request = request
	var _result message.MessageServiceGetChatRecordResult
	if err = p.c.Call(ctx, "GetChatRecord", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}
