// Code generated by protoc-gen-go-ttrpc. DO NOT EDIT.
// source: services/events/v1/events.proto
package events

import (
	context "context"
	types "github.com/containerd/containerd/api/types"
	ttrpc "github.com/containerd/ttrpc"
	emptypb "google.golang.org/protobuf/types/known/emptypb"
)

type TTRPCEventsService interface {
	Publish(context.Context, *PublishRequest) (*emptypb.Empty, error)
	Forward(context.Context, *ForwardRequest) (*emptypb.Empty, error)
	Subscribe(context.Context, *SubscribeRequest, TTRPCEvents_SubscribeServer) error
}

type TTRPCEvents_SubscribeServer interface {
	Send(*types.Envelope) error
	ttrpc.StreamServer
}

type ttrpceventsSubscribeServer struct {
	ttrpc.StreamServer
}

func (x *ttrpceventsSubscribeServer) Send(m *types.Envelope) error {
	return x.StreamServer.SendMsg(m)
}

func RegisterTTRPCEventsService(srv *ttrpc.Server, svc TTRPCEventsService) {
	srv.RegisterService("containerd.services.events.v1.Events", &ttrpc.ServiceDesc{
		Methods: map[string]ttrpc.Method{
			"Publish": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) {
				var req PublishRequest
				if err := unmarshal(&req); err != nil {
					return nil, err
				}
				return svc.Publish(ctx, &req)
			},
			"Forward": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) {
				var req ForwardRequest
				if err := unmarshal(&req); err != nil {
					return nil, err
				}
				return svc.Forward(ctx, &req)
			},
		},
		Streams: map[string]ttrpc.Stream{
			"Subscribe": {
				Handler: func(ctx context.Context, stream ttrpc.StreamServer) (interface{}, error) {
					m := new(SubscribeRequest)
					if err := stream.RecvMsg(m); err != nil {
						return nil, err
					}
					return nil, svc.Subscribe(ctx, m, &ttrpceventsSubscribeServer{stream})
				},
				StreamingClient: false,
				StreamingServer: true,
			},
		},
	})
}

type TTRPCEventsClient interface {
	Publish(context.Context, *PublishRequest) (*emptypb.Empty, error)
	Forward(context.Context, *ForwardRequest) (*emptypb.Empty, error)
	Subscribe(context.Context, *SubscribeRequest) (TTRPCEvents_SubscribeClient, error)
}

type ttrpceventsClient struct {
	client *ttrpc.Client
}

func NewTTRPCEventsClient(client *ttrpc.Client) TTRPCEventsClient {
	return &ttrpceventsClient{
		client: client,
	}
}

func (c *ttrpceventsClient) Publish(ctx context.Context, req *PublishRequest) (*emptypb.Empty, error) {
	var resp emptypb.Empty
	if err := c.client.Call(ctx, "containerd.services.events.v1.Events", "Publish", req, &resp); err != nil {
		return nil, err
	}
	return &resp, nil
}

func (c *ttrpceventsClient) Forward(ctx context.Context, req *ForwardRequest) (*emptypb.Empty, error) {
	var resp emptypb.Empty
	if err := c.client.Call(ctx, "containerd.services.events.v1.Events", "Forward", req, &resp); err != nil {
		return nil, err
	}
	return &resp, nil
}

func (c *ttrpceventsClient) Subscribe(ctx context.Context, req *SubscribeRequest) (TTRPCEvents_SubscribeClient, error) {
	stream, err := c.client.NewStream(ctx, &ttrpc.StreamDesc{
		StreamingClient: false,
		StreamingServer: true,
	}, "containerd.services.events.v1.Events", "Subscribe", req)
	if err != nil {
		return nil, err
	}
	x := &ttrpceventsSubscribeClient{stream}
	return x, nil
}

type TTRPCEvents_SubscribeClient interface {
	Recv() (*types.Envelope, error)
	ttrpc.ClientStream
}

type ttrpceventsSubscribeClient struct {
	ttrpc.ClientStream
}

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