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

package feedsrv

import (
	"context"
	"fmt"
	feed "github.com/a76yyyy/tiktok/kitex_gen/feed"
	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"
)

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

var feedSrvServiceInfo = NewServiceInfo()

func NewServiceInfo() *kitex.ServiceInfo {
	serviceName := "FeedSrv"
	handlerType := (*feed.FeedSrv)(nil)
	methods := map[string]kitex.MethodInfo{
		"GetUserFeed":  kitex.NewMethodInfo(getUserFeedHandler, newGetUserFeedArgs, newGetUserFeedResult, false),
		"GetVideoById": kitex.NewMethodInfo(getVideoByIdHandler, newGetVideoByIdArgs, newGetVideoByIdResult, false),
	}
	extra := map[string]interface{}{
		"PackageName": "feed",
	}
	svcInfo := &kitex.ServiceInfo{
		ServiceName:     serviceName,
		HandlerType:     handlerType,
		Methods:         methods,
		PayloadCodec:    kitex.Protobuf,
		KiteXGenVersion: "v0.4.4",
		Extra:           extra,
	}
	return svcInfo
}

func getUserFeedHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	switch s := arg.(type) {
	case *streaming.Args:
		st := s.Stream
		req := new(feed.DouyinFeedRequest)
		if err := st.RecvMsg(req); err != nil {
			return err
		}
		resp, err := handler.(feed.FeedSrv).GetUserFeed(ctx, req)
		if err != nil {
			return err
		}
		if err := st.SendMsg(resp); err != nil {
			return err
		}
	case *GetUserFeedArgs:
		success, err := handler.(feed.FeedSrv).GetUserFeed(ctx, s.Req)
		if err != nil {
			return err
		}
		realResult := result.(*GetUserFeedResult)
		realResult.Success = success
	}
	return nil
}
func newGetUserFeedArgs() interface{} {
	return &GetUserFeedArgs{}
}

func newGetUserFeedResult() interface{} {
	return &GetUserFeedResult{}
}

type GetUserFeedArgs struct {
	Req *feed.DouyinFeedRequest
}

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

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

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

func (p *GetUserFeedArgs) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetReq() {
		return out, fmt.Errorf("No req in GetUserFeedArgs")
	}
	return proto.Marshal(p.Req)
}

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

var GetUserFeedArgs_Req_DEFAULT *feed.DouyinFeedRequest

func (p *GetUserFeedArgs) GetReq() *feed.DouyinFeedRequest {
	if !p.IsSetReq() {
		return GetUserFeedArgs_Req_DEFAULT
	}
	return p.Req
}

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

type GetUserFeedResult struct {
	Success *feed.DouyinFeedResponse
}

var GetUserFeedResult_Success_DEFAULT *feed.DouyinFeedResponse

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

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

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

func (p *GetUserFeedResult) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetSuccess() {
		return out, fmt.Errorf("No req in GetUserFeedResult")
	}
	return proto.Marshal(p.Success)
}

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

func (p *GetUserFeedResult) GetSuccess() *feed.DouyinFeedResponse {
	if !p.IsSetSuccess() {
		return GetUserFeedResult_Success_DEFAULT
	}
	return p.Success
}

func (p *GetUserFeedResult) SetSuccess(x interface{}) {
	p.Success = x.(*feed.DouyinFeedResponse)
}

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

func getVideoByIdHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	switch s := arg.(type) {
	case *streaming.Args:
		st := s.Stream
		req := new(feed.VideoIdRequest)
		if err := st.RecvMsg(req); err != nil {
			return err
		}
		resp, err := handler.(feed.FeedSrv).GetVideoById(ctx, req)
		if err != nil {
			return err
		}
		if err := st.SendMsg(resp); err != nil {
			return err
		}
	case *GetVideoByIdArgs:
		success, err := handler.(feed.FeedSrv).GetVideoById(ctx, s.Req)
		if err != nil {
			return err
		}
		realResult := result.(*GetVideoByIdResult)
		realResult.Success = success
	}
	return nil
}
func newGetVideoByIdArgs() interface{} {
	return &GetVideoByIdArgs{}
}

func newGetVideoByIdResult() interface{} {
	return &GetVideoByIdResult{}
}

type GetVideoByIdArgs struct {
	Req *feed.VideoIdRequest
}

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

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

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

func (p *GetVideoByIdArgs) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetReq() {
		return out, fmt.Errorf("No req in GetVideoByIdArgs")
	}
	return proto.Marshal(p.Req)
}

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

var GetVideoByIdArgs_Req_DEFAULT *feed.VideoIdRequest

func (p *GetVideoByIdArgs) GetReq() *feed.VideoIdRequest {
	if !p.IsSetReq() {
		return GetVideoByIdArgs_Req_DEFAULT
	}
	return p.Req
}

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

type GetVideoByIdResult struct {
	Success *feed.Video
}

var GetVideoByIdResult_Success_DEFAULT *feed.Video

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

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

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

func (p *GetVideoByIdResult) Marshal(out []byte) ([]byte, error) {
	if !p.IsSetSuccess() {
		return out, fmt.Errorf("No req in GetVideoByIdResult")
	}
	return proto.Marshal(p.Success)
}

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

func (p *GetVideoByIdResult) GetSuccess() *feed.Video {
	if !p.IsSetSuccess() {
		return GetVideoByIdResult_Success_DEFAULT
	}
	return p.Success
}

func (p *GetVideoByIdResult) SetSuccess(x interface{}) {
	p.Success = x.(*feed.Video)
}

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

type kClient struct {
	c client.Client
}

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

func (p *kClient) GetUserFeed(ctx context.Context, Req *feed.DouyinFeedRequest) (r *feed.DouyinFeedResponse, err error) {
	var _args GetUserFeedArgs
	_args.Req = Req
	var _result GetUserFeedResult
	if err = p.c.Call(ctx, "GetUserFeed", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}

func (p *kClient) GetVideoById(ctx context.Context, Req *feed.VideoIdRequest) (r *feed.Video, err error) {
	var _args GetVideoByIdArgs
	_args.Req = Req
	var _result GetVideoByIdResult
	if err = p.c.Call(ctx, "GetVideoById", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}
