//  Copyright 2019 Google
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.

// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.6.2
// - protoc             v7.35.1
// source: snapshot_service.proto

package cloud_vmm

import (
	context "context"
	grpc "google.golang.org/grpc"
	codes "google.golang.org/grpc/codes"
	status "google.golang.org/grpc/status"
)

// 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.64.0 or later.
const _ = grpc.SupportPackageIsVersion9

const (
	SnapshotService_CreateConnection_FullMethodName         = "/cloud.vmm.SnapshotService/CreateConnection"
	SnapshotService_HandleResponsesFromGuest_FullMethodName = "/cloud.vmm.SnapshotService/HandleResponsesFromGuest"
)

// SnapshotServiceClient is the client API for SnapshotService 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.
//
// Service to handle pre and post snapshot requests from vanadium.
type SnapshotServiceClient interface {
	// The client is expected to first send a "GuestReady" message, indicating
	// they are available and establishing the connection that vanadium writes
	// requests to the agent on.
	CreateConnection(ctx context.Context, in *GuestReady, opts ...grpc.CallOption) (grpc.ServerStreamingClient[GuestMessage], error)
	// Handles the agent's responses to the above requests.
	HandleResponsesFromGuest(ctx context.Context, in *SnapshotResponse, opts ...grpc.CallOption) (*ServerAck, error)
}

type snapshotServiceClient struct {
	cc grpc.ClientConnInterface
}

func NewSnapshotServiceClient(cc grpc.ClientConnInterface) SnapshotServiceClient {
	return &snapshotServiceClient{cc}
}

func (c *snapshotServiceClient) CreateConnection(ctx context.Context, in *GuestReady, opts ...grpc.CallOption) (grpc.ServerStreamingClient[GuestMessage], error) {
	cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
	stream, err := c.cc.NewStream(ctx, &SnapshotService_ServiceDesc.Streams[0], SnapshotService_CreateConnection_FullMethodName, cOpts...)
	if err != nil {
		return nil, err
	}
	x := &grpc.GenericClientStream[GuestReady, GuestMessage]{ClientStream: stream}
	if err := x.ClientStream.SendMsg(in); err != nil {
		return nil, err
	}
	if err := x.ClientStream.CloseSend(); err != nil {
		return nil, err
	}
	return x, nil
}

// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type SnapshotService_CreateConnectionClient = grpc.ServerStreamingClient[GuestMessage]

func (c *snapshotServiceClient) HandleResponsesFromGuest(ctx context.Context, in *SnapshotResponse, opts ...grpc.CallOption) (*ServerAck, error) {
	cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
	out := new(ServerAck)
	err := c.cc.Invoke(ctx, SnapshotService_HandleResponsesFromGuest_FullMethodName, in, out, cOpts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

// SnapshotServiceServer is the server API for SnapshotService service.
// All implementations must embed UnimplementedSnapshotServiceServer
// for forward compatibility.
//
// Service to handle pre and post snapshot requests from vanadium.
type SnapshotServiceServer interface {
	// The client is expected to first send a "GuestReady" message, indicating
	// they are available and establishing the connection that vanadium writes
	// requests to the agent on.
	CreateConnection(*GuestReady, grpc.ServerStreamingServer[GuestMessage]) error
	// Handles the agent's responses to the above requests.
	HandleResponsesFromGuest(context.Context, *SnapshotResponse) (*ServerAck, error)
	mustEmbedUnimplementedSnapshotServiceServer()
}

// UnimplementedSnapshotServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedSnapshotServiceServer struct{}

func (UnimplementedSnapshotServiceServer) CreateConnection(*GuestReady, grpc.ServerStreamingServer[GuestMessage]) error {
	return status.Error(codes.Unimplemented, "method CreateConnection not implemented")
}
func (UnimplementedSnapshotServiceServer) HandleResponsesFromGuest(context.Context, *SnapshotResponse) (*ServerAck, error) {
	return nil, status.Error(codes.Unimplemented, "method HandleResponsesFromGuest not implemented")
}
func (UnimplementedSnapshotServiceServer) mustEmbedUnimplementedSnapshotServiceServer() {}
func (UnimplementedSnapshotServiceServer) testEmbeddedByValue()                         {}

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

func RegisterSnapshotServiceServer(s grpc.ServiceRegistrar, srv SnapshotServiceServer) {
	// If the following call panics, it indicates UnimplementedSnapshotServiceServer was
	// embedded by pointer and is nil.  This will cause panics if an
	// unimplemented method is ever invoked, so we test this at initialization
	// time to prevent it from happening at runtime later due to I/O.
	if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
		t.testEmbeddedByValue()
	}
	s.RegisterService(&SnapshotService_ServiceDesc, srv)
}

func _SnapshotService_CreateConnection_Handler(srv interface{}, stream grpc.ServerStream) error {
	m := new(GuestReady)
	if err := stream.RecvMsg(m); err != nil {
		return err
	}
	return srv.(SnapshotServiceServer).CreateConnection(m, &grpc.GenericServerStream[GuestReady, GuestMessage]{ServerStream: stream})
}

// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type SnapshotService_CreateConnectionServer = grpc.ServerStreamingServer[GuestMessage]

func _SnapshotService_HandleResponsesFromGuest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(SnapshotResponse)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(SnapshotServiceServer).HandleResponsesFromGuest(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: SnapshotService_HandleResponsesFromGuest_FullMethodName,
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(SnapshotServiceServer).HandleResponsesFromGuest(ctx, req.(*SnapshotResponse))
	}
	return interceptor(ctx, in, info, handler)
}

// SnapshotService_ServiceDesc is the grpc.ServiceDesc for SnapshotService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var SnapshotService_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "cloud.vmm.SnapshotService",
	HandlerType: (*SnapshotServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "HandleResponsesFromGuest",
			Handler:    _SnapshotService_HandleResponsesFromGuest_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "CreateConnection",
			Handler:       _SnapshotService_CreateConnection_Handler,
			ServerStreams: true,
		},
	},
	Metadata: "snapshot_service.proto",
}
