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

package ratingservice

import (
	"context"
	ratings "github.com/cloudwego/biz-demo/bookinfo/kitex_gen/cwg/bookinfo/ratings"
	client "github.com/cloudwego/kitex/client"
	kitex "github.com/cloudwego/kitex/pkg/serviceinfo"
)

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

var ratingServiceServiceInfo = NewServiceInfo()

func NewServiceInfo() *kitex.ServiceInfo {
	serviceName := "RatingService"
	handlerType := (*ratings.RatingService)(nil)
	methods := map[string]kitex.MethodInfo{
		"ratings": kitex.NewMethodInfo(ratingsHandler, newRatingServiceRatingsArgs, newRatingServiceRatingsResult, false),
	}
	extra := map[string]interface{}{
		"PackageName": "ratings",
	}
	svcInfo := &kitex.ServiceInfo{
		ServiceName:     serviceName,
		HandlerType:     handlerType,
		Methods:         methods,
		PayloadCodec:    kitex.Thrift,
		KiteXGenVersion: "v0.4.2",
		Extra:           extra,
	}
	return svcInfo
}

func ratingsHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	realArg := arg.(*ratings.RatingServiceRatingsArgs)
	realResult := result.(*ratings.RatingServiceRatingsResult)
	success, err := handler.(ratings.RatingService).Ratings(ctx, realArg.Req)
	if err != nil {
		return err
	}
	realResult.Success = success
	return nil
}
func newRatingServiceRatingsArgs() interface{} {
	return ratings.NewRatingServiceRatingsArgs()
}

func newRatingServiceRatingsResult() interface{} {
	return ratings.NewRatingServiceRatingsResult()
}

type kClient struct {
	c client.Client
}

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

func (p *kClient) Ratings(ctx context.Context, req *ratings.RatingReq) (r *ratings.RatingResp, err error) {
	var _args ratings.RatingServiceRatingsArgs
	_args.Req = req
	var _result ratings.RatingServiceRatingsResult
	if err = p.c.Call(ctx, "ratings", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}
