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

package counterservice

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 counterServiceServiceInfo
}

var counterServiceServiceInfo = NewServiceInfo()

func NewServiceInfo() *kitex.ServiceInfo {
	serviceName := "CounterService"
	handlerType := (*rpc.CounterService)(nil)
	methods := map[string]kitex.MethodInfo{
		"Increment": kitex.NewMethodInfo(incrementHandler, newCounterServiceIncrementArgs, newCounterServiceIncrementResult, false),
		"Fetch":     kitex.NewMethodInfo(fetchHandler, newCounterServiceFetchArgs, newCounterServiceFetchResult, 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 incrementHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	realArg := arg.(*rpc.CounterServiceIncrementArgs)
	realResult := result.(*rpc.CounterServiceIncrementResult)
	success, err := handler.(rpc.CounterService).Increment(ctx, realArg.Req)
	if err != nil {
		return err
	}
	realResult.Success = success
	return nil
}
func newCounterServiceIncrementArgs() interface{} {
	return rpc.NewCounterServiceIncrementArgs()
}

func newCounterServiceIncrementResult() interface{} {
	return rpc.NewCounterServiceIncrementResult()
}

func fetchHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
	realArg := arg.(*rpc.CounterServiceFetchArgs)
	realResult := result.(*rpc.CounterServiceFetchResult)
	success, err := handler.(rpc.CounterService).Fetch(ctx, realArg.Req)
	if err != nil {
		return err
	}
	realResult.Success = success
	return nil
}
func newCounterServiceFetchArgs() interface{} {
	return rpc.NewCounterServiceFetchArgs()
}

func newCounterServiceFetchResult() interface{} {
	return rpc.NewCounterServiceFetchResult()
}

type kClient struct {
	c client.Client
}

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

func (p *kClient) Increment(ctx context.Context, req *rpc.CounterIncRequest) (r *rpc.CounterNopResponse, err error) {
	var _args rpc.CounterServiceIncrementArgs
	_args.Req = req
	var _result rpc.CounterServiceIncrementResult
	if err = p.c.Call(ctx, "Increment", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}

func (p *kClient) Fetch(ctx context.Context, req *rpc.CounterGetRequest) (r *rpc.CounterGetResponse, err error) {
	var _args rpc.CounterServiceFetchArgs
	_args.Req = req
	var _result rpc.CounterServiceFetchResult
	if err = p.c.Call(ctx, "Fetch", &_args, &_result); err != nil {
		return
	}
	return _result.GetSuccess(), nil
}
