package scdbpb

import (
	context "context"
	grpc "google.golang.org/grpc"
	codes "google.golang.org/grpc/codes"
	status "google.golang.org/grpc/status"
	emptypb "google.golang.org/protobuf/types/known/emptypb"
)

// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7

const (
	Scdb_Ping_FullMethodName        = "/scdbpb.Scdb/Ping"
	Scdb_Save_FullMethodName        = "/scdbpb.Scdb/Save"
	Scdb_Get_FullMethodName         = "/scdbpb.Scdb/Get"
	Scdb_Del_FullMethodName         = "/scdbpb.Scdb/Del"
	Scdb_Close_FullMethodName       = "/scdbpb.Scdb/Close"
	Scdb_Transaction_FullMethodName = "/scdbpb.Scdb/Transaction"
)

// ScdbClient is the client API for Scdb service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type ScdbClient interface {
	Ping(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error)
	Save(ctx context.Context, in *KV, opts ...grpc.CallOption) (*Result, error)
	Get(ctx context.Context, in *KV, opts ...grpc.CallOption) (*Result, error)
	Del(ctx context.Context, in *KV, opts ...grpc.CallOption) (*Result, error)
	Close(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*Result, error)
	Transaction(ctx context.Context, opts ...grpc.CallOption) (Scdb_TransactionClient, error)
}

type scdbClient struct {
	cc grpc.ClientConnInterface
}

func NewScdbClient(cc grpc.ClientConnInterface) ScdbClient {
	return &scdbClient{cc}
}

func (c *scdbClient) Ping(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) {
	out := new(emptypb.Empty)
	err := c.cc.Invoke(ctx, Scdb_Ping_FullMethodName, in, out, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *scdbClient) Save(ctx context.Context, in *KV, opts ...grpc.CallOption) (*Result, error) {
	out := new(Result)
	err := c.cc.Invoke(ctx, Scdb_Save_FullMethodName, in, out, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *scdbClient) Get(ctx context.Context, in *KV, opts ...grpc.CallOption) (*Result, error) {
	out := new(Result)
	err := c.cc.Invoke(ctx, Scdb_Get_FullMethodName, in, out, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *scdbClient) Del(ctx context.Context, in *KV, opts ...grpc.CallOption) (*Result, error) {
	out := new(Result)
	err := c.cc.Invoke(ctx, Scdb_Del_FullMethodName, in, out, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *scdbClient) Close(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*Result, error) {
	out := new(Result)
	err := c.cc.Invoke(ctx, Scdb_Close_FullMethodName, in, out, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *scdbClient) Transaction(ctx context.Context, opts ...grpc.CallOption) (Scdb_TransactionClient, error) {
	stream, err := c.cc.NewStream(ctx, &Scdb_ServiceDesc.Streams[0], Scdb_Transaction_FullMethodName, opts...)
	if err != nil {
		return nil, err
	}
	x := &scdbTransactionClient{stream}
	return x, nil
}

type Scdb_TransactionClient interface {
	Send(*TxIn) error
	Recv() (*TxOut, error)
	grpc.ClientStream
}

type scdbTransactionClient struct {
	grpc.ClientStream
}

func (x *scdbTransactionClient) Send(m *TxIn) error {
	return x.ClientStream.SendMsg(m)
}

func (x *scdbTransactionClient) Recv() (*TxOut, error) {
	m := new(TxOut)
	if err := x.ClientStream.RecvMsg(m); err != nil {
		return nil, err
	}
	return m, nil
}

// ScdbServer is the server API for Scdb service.
// All implementations should embed UnimplementedScdbServer
// for forward compatibility
type ScdbServer interface {
	Ping(context.Context, *emptypb.Empty) (*emptypb.Empty, error)
	Save(context.Context, *KV) (*Result, error)
	Get(context.Context, *KV) (*Result, error)
	Del(context.Context, *KV) (*Result, error)
	Close(context.Context, *emptypb.Empty) (*Result, error)
	Transaction(Scdb_TransactionServer) error
}

// UnimplementedScdbServer should be embedded to have forward compatible implementations.
type UnimplementedScdbServer struct {
}

func (UnimplementedScdbServer) Ping(context.Context, *emptypb.Empty) (*emptypb.Empty, error) {
	return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented")
}
func (UnimplementedScdbServer) Save(context.Context, *KV) (*Result, error) {
	return nil, status.Errorf(codes.Unimplemented, "method Save not implemented")
}
func (UnimplementedScdbServer) Get(context.Context, *KV) (*Result, error) {
	return nil, status.Errorf(codes.Unimplemented, "method Get not implemented")
}
func (UnimplementedScdbServer) Del(context.Context, *KV) (*Result, error) {
	return nil, status.Errorf(codes.Unimplemented, "method Del not implemented")
}
func (UnimplementedScdbServer) Close(context.Context, *emptypb.Empty) (*Result, error) {
	return nil, status.Errorf(codes.Unimplemented, "method Close not implemented")
}
func (UnimplementedScdbServer) Transaction(Scdb_TransactionServer) error {
	return status.Errorf(codes.Unimplemented, "method Transaction not implemented")
}

// UnsafeScdbServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to ScdbServer will
// result in compilation errors.
type UnsafeScdbServer interface {
	mustEmbedUnimplementedScdbServer()
}

func RegisterScdbServer(s grpc.ServiceRegistrar, srv ScdbServer) {
	s.RegisterService(&Scdb_ServiceDesc, srv)
}

func _Scdb_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(emptypb.Empty)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(ScdbServer).Ping(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: Scdb_Ping_FullMethodName,
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(ScdbServer).Ping(ctx, req.(*emptypb.Empty))
	}
	return interceptor(ctx, in, info, handler)
}

func _Scdb_Save_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(KV)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(ScdbServer).Save(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: Scdb_Save_FullMethodName,
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(ScdbServer).Save(ctx, req.(*KV))
	}
	return interceptor(ctx, in, info, handler)
}

func _Scdb_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(KV)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(ScdbServer).Get(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: Scdb_Get_FullMethodName,
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(ScdbServer).Get(ctx, req.(*KV))
	}
	return interceptor(ctx, in, info, handler)
}

func _Scdb_Del_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(KV)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(ScdbServer).Del(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: Scdb_Del_FullMethodName,
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(ScdbServer).Del(ctx, req.(*KV))
	}
	return interceptor(ctx, in, info, handler)
}

func _Scdb_Close_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(emptypb.Empty)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(ScdbServer).Close(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: Scdb_Close_FullMethodName,
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(ScdbServer).Close(ctx, req.(*emptypb.Empty))
	}
	return interceptor(ctx, in, info, handler)
}

func _Scdb_Transaction_Handler(srv interface{}, stream grpc.ServerStream) error {
	return srv.(ScdbServer).Transaction(&scdbTransactionServer{stream})
}

type Scdb_TransactionServer interface {
	Send(*TxOut) error
	Recv() (*TxIn, error)
	grpc.ServerStream
}

type scdbTransactionServer struct {
	grpc.ServerStream
}

func (x *scdbTransactionServer) Send(m *TxOut) error {
	return x.ServerStream.SendMsg(m)
}

func (x *scdbTransactionServer) Recv() (*TxIn, error) {
	m := new(TxIn)
	if err := x.ServerStream.RecvMsg(m); err != nil {
		return nil, err
	}
	return m, nil
}

// Scdb_ServiceDesc is the grpc.ServiceDesc for Scdb service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Scdb_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "scdbpb.Scdb",
	HandlerType: (*ScdbServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Ping",
			Handler:    _Scdb_Ping_Handler,
		},
		{
			MethodName: "Save",
			Handler:    _Scdb_Save_Handler,
		},
		{
			MethodName: "Get",
			Handler:    _Scdb_Get_Handler,
		},
		{
			MethodName: "Del",
			Handler:    _Scdb_Del_Handler,
		},
		{
			MethodName: "Close",
			Handler:    _Scdb_Close_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "Transaction",
			Handler:       _Scdb_Transaction_Handler,
			ServerStreams: true,
			ClientStreams: true,
		},
	},
	Metadata: "sc/sc.proto",
}
