// Code generated by protoc-gen-srpc. DO NOT EDIT.
// protoc-gen-srpc version: v0.39.7
// source: github.com/aperturerobotics/bifrost/stream/api/api.proto

package stream_api

import (
	context "context"

	srpc "github.com/aperturerobotics/starpc/srpc"
)

type SRPCStreamServiceClient interface {
	// SRPCClient returns the underlying SRPC client.
	SRPCClient() srpc.Client

	// ForwardStreams forwards streams to the target multiaddress.
	// Handles HandleMountedStream directives by contacting the target.
	ForwardStreams(ctx context.Context, in *ForwardStreamsRequest) (SRPCStreamService_ForwardStreamsClient, error)
	// ListenStreams listens for connections to the multiaddress.
	// Forwards the connections to a remote peer with a protocol ID.
	ListenStreams(ctx context.Context, in *ListenStreamsRequest) (SRPCStreamService_ListenStreamsClient, error)
	// AcceptStream accepts an incoming stream.
	// Stream data is sent over the request / response streams.
	AcceptStream(ctx context.Context) (SRPCStreamService_AcceptStreamClient, error)
	// DialStream dials a outgoing stream.
	// Stream data is sent over the request / response streams.
	DialStream(ctx context.Context) (SRPCStreamService_DialStreamClient, error)
}

type srpcStreamServiceClient struct {
	cc        srpc.Client
	serviceID string
}

func NewSRPCStreamServiceClient(cc srpc.Client) SRPCStreamServiceClient {
	return &srpcStreamServiceClient{cc: cc, serviceID: SRPCStreamServiceServiceID}
}

func NewSRPCStreamServiceClientWithServiceID(cc srpc.Client, serviceID string) SRPCStreamServiceClient {
	if serviceID == "" {
		serviceID = SRPCStreamServiceServiceID
	}
	return &srpcStreamServiceClient{cc: cc, serviceID: serviceID}
}

func (c *srpcStreamServiceClient) SRPCClient() srpc.Client { return c.cc }

func (c *srpcStreamServiceClient) ForwardStreams(ctx context.Context, in *ForwardStreamsRequest) (SRPCStreamService_ForwardStreamsClient, error) {
	stream, err := c.cc.NewStream(ctx, c.serviceID, "ForwardStreams", in)
	if err != nil {
		return nil, err
	}
	strm := &srpcStreamService_ForwardStreamsClient{stream}
	if err := strm.CloseSend(); err != nil {
		return nil, err
	}
	return strm, nil
}

type SRPCStreamService_ForwardStreamsClient interface {
	srpc.Stream
	Recv() (*ForwardStreamsResponse, error)
	RecvTo(*ForwardStreamsResponse) error
}

type srpcStreamService_ForwardStreamsClient struct {
	srpc.Stream
}

func (x *srpcStreamService_ForwardStreamsClient) Recv() (*ForwardStreamsResponse, error) {
	m := new(ForwardStreamsResponse)
	if err := x.MsgRecv(m); err != nil {
		return nil, err
	}
	return m, nil
}

func (x *srpcStreamService_ForwardStreamsClient) RecvTo(m *ForwardStreamsResponse) error {
	return x.MsgRecv(m)
}

func (c *srpcStreamServiceClient) ListenStreams(ctx context.Context, in *ListenStreamsRequest) (SRPCStreamService_ListenStreamsClient, error) {
	stream, err := c.cc.NewStream(ctx, c.serviceID, "ListenStreams", in)
	if err != nil {
		return nil, err
	}
	strm := &srpcStreamService_ListenStreamsClient{stream}
	if err := strm.CloseSend(); err != nil {
		return nil, err
	}
	return strm, nil
}

type SRPCStreamService_ListenStreamsClient interface {
	srpc.Stream
	Recv() (*ListenStreamsResponse, error)
	RecvTo(*ListenStreamsResponse) error
}

type srpcStreamService_ListenStreamsClient struct {
	srpc.Stream
}

func (x *srpcStreamService_ListenStreamsClient) Recv() (*ListenStreamsResponse, error) {
	m := new(ListenStreamsResponse)
	if err := x.MsgRecv(m); err != nil {
		return nil, err
	}
	return m, nil
}

func (x *srpcStreamService_ListenStreamsClient) RecvTo(m *ListenStreamsResponse) error {
	return x.MsgRecv(m)
}

func (c *srpcStreamServiceClient) AcceptStream(ctx context.Context) (SRPCStreamService_AcceptStreamClient, error) {
	stream, err := c.cc.NewStream(ctx, c.serviceID, "AcceptStream", nil)
	if err != nil {
		return nil, err
	}
	strm := &srpcStreamService_AcceptStreamClient{stream}
	return strm, nil
}

type SRPCStreamService_AcceptStreamClient interface {
	srpc.Stream
	Send(*AcceptStreamRequest) error
	Recv() (*AcceptStreamResponse, error)
	RecvTo(*AcceptStreamResponse) error
}

type srpcStreamService_AcceptStreamClient struct {
	srpc.Stream
}

func (x *srpcStreamService_AcceptStreamClient) Send(m *AcceptStreamRequest) error {
	if m == nil {
		return nil
	}
	return x.MsgSend(m)
}

func (x *srpcStreamService_AcceptStreamClient) Recv() (*AcceptStreamResponse, error) {
	m := new(AcceptStreamResponse)
	if err := x.MsgRecv(m); err != nil {
		return nil, err
	}
	return m, nil
}

func (x *srpcStreamService_AcceptStreamClient) RecvTo(m *AcceptStreamResponse) error {
	return x.MsgRecv(m)
}

func (c *srpcStreamServiceClient) DialStream(ctx context.Context) (SRPCStreamService_DialStreamClient, error) {
	stream, err := c.cc.NewStream(ctx, c.serviceID, "DialStream", nil)
	if err != nil {
		return nil, err
	}
	strm := &srpcStreamService_DialStreamClient{stream}
	return strm, nil
}

type SRPCStreamService_DialStreamClient interface {
	srpc.Stream
	Send(*DialStreamRequest) error
	Recv() (*DialStreamResponse, error)
	RecvTo(*DialStreamResponse) error
}

type srpcStreamService_DialStreamClient struct {
	srpc.Stream
}

func (x *srpcStreamService_DialStreamClient) Send(m *DialStreamRequest) error {
	if m == nil {
		return nil
	}
	return x.MsgSend(m)
}

func (x *srpcStreamService_DialStreamClient) Recv() (*DialStreamResponse, error) {
	m := new(DialStreamResponse)
	if err := x.MsgRecv(m); err != nil {
		return nil, err
	}
	return m, nil
}

func (x *srpcStreamService_DialStreamClient) RecvTo(m *DialStreamResponse) error {
	return x.MsgRecv(m)
}

type SRPCStreamServiceServer interface {
	// ForwardStreams forwards streams to the target multiaddress.
	// Handles HandleMountedStream directives by contacting the target.
	ForwardStreams(*ForwardStreamsRequest, SRPCStreamService_ForwardStreamsStream) error
	// ListenStreams listens for connections to the multiaddress.
	// Forwards the connections to a remote peer with a protocol ID.
	ListenStreams(*ListenStreamsRequest, SRPCStreamService_ListenStreamsStream) error
	// AcceptStream accepts an incoming stream.
	// Stream data is sent over the request / response streams.
	AcceptStream(SRPCStreamService_AcceptStreamStream) error
	// DialStream dials a outgoing stream.
	// Stream data is sent over the request / response streams.
	DialStream(SRPCStreamService_DialStreamStream) error
}

const SRPCStreamServiceServiceID = "stream.api.StreamService"

type SRPCStreamServiceHandler struct {
	serviceID string
	impl      SRPCStreamServiceServer
}

// NewSRPCStreamServiceHandler constructs a new RPC handler.
// serviceID: if empty, uses default: stream.api.StreamService
func NewSRPCStreamServiceHandler(impl SRPCStreamServiceServer, serviceID string) srpc.Handler {
	if serviceID == "" {
		serviceID = SRPCStreamServiceServiceID
	}
	return &SRPCStreamServiceHandler{impl: impl, serviceID: serviceID}
}

// SRPCRegisterStreamService registers the implementation with the mux.
// Uses the default serviceID: stream.api.StreamService
func SRPCRegisterStreamService(mux srpc.Mux, impl SRPCStreamServiceServer) error {
	return mux.Register(NewSRPCStreamServiceHandler(impl, ""))
}

func (d *SRPCStreamServiceHandler) GetServiceID() string { return d.serviceID }

func (SRPCStreamServiceHandler) GetMethodIDs() []string {
	return []string{
		"ForwardStreams",
		"ListenStreams",
		"AcceptStream",
		"DialStream",
	}
}

func (d *SRPCStreamServiceHandler) InvokeMethod(
	serviceID, methodID string,
	strm srpc.Stream,
) (bool, error) {
	if serviceID != "" && serviceID != d.GetServiceID() {
		return false, nil
	}

	switch methodID {
	case "ForwardStreams":
		return true, d.InvokeMethod_ForwardStreams(d.impl, strm)
	case "ListenStreams":
		return true, d.InvokeMethod_ListenStreams(d.impl, strm)
	case "AcceptStream":
		return true, d.InvokeMethod_AcceptStream(d.impl, strm)
	case "DialStream":
		return true, d.InvokeMethod_DialStream(d.impl, strm)
	default:
		return false, nil
	}
}

func (SRPCStreamServiceHandler) InvokeMethod_ForwardStreams(impl SRPCStreamServiceServer, strm srpc.Stream) error {
	req := new(ForwardStreamsRequest)
	if err := strm.MsgRecv(req); err != nil {
		return err
	}
	serverStrm := &srpcStreamService_ForwardStreamsStream{strm}
	return impl.ForwardStreams(req, serverStrm)
}

func (SRPCStreamServiceHandler) InvokeMethod_ListenStreams(impl SRPCStreamServiceServer, strm srpc.Stream) error {
	req := new(ListenStreamsRequest)
	if err := strm.MsgRecv(req); err != nil {
		return err
	}
	serverStrm := &srpcStreamService_ListenStreamsStream{strm}
	return impl.ListenStreams(req, serverStrm)
}

func (SRPCStreamServiceHandler) InvokeMethod_AcceptStream(impl SRPCStreamServiceServer, strm srpc.Stream) error {
	clientStrm := &srpcStreamService_AcceptStreamStream{strm}
	return impl.AcceptStream(clientStrm)
}

func (SRPCStreamServiceHandler) InvokeMethod_DialStream(impl SRPCStreamServiceServer, strm srpc.Stream) error {
	clientStrm := &srpcStreamService_DialStreamStream{strm}
	return impl.DialStream(clientStrm)
}

type SRPCStreamService_ForwardStreamsStream interface {
	srpc.Stream
	Send(*ForwardStreamsResponse) error
	SendAndClose(*ForwardStreamsResponse) error
}

type srpcStreamService_ForwardStreamsStream struct {
	srpc.Stream
}

func (x *srpcStreamService_ForwardStreamsStream) Send(m *ForwardStreamsResponse) error {
	return x.MsgSend(m)
}

func (x *srpcStreamService_ForwardStreamsStream) SendAndClose(m *ForwardStreamsResponse) error {
	if m != nil {
		if err := x.MsgSend(m); err != nil {
			return err
		}
	}
	return x.CloseSend()
}

type SRPCStreamService_ListenStreamsStream interface {
	srpc.Stream
	Send(*ListenStreamsResponse) error
	SendAndClose(*ListenStreamsResponse) error
}

type srpcStreamService_ListenStreamsStream struct {
	srpc.Stream
}

func (x *srpcStreamService_ListenStreamsStream) Send(m *ListenStreamsResponse) error {
	return x.MsgSend(m)
}

func (x *srpcStreamService_ListenStreamsStream) SendAndClose(m *ListenStreamsResponse) error {
	if m != nil {
		if err := x.MsgSend(m); err != nil {
			return err
		}
	}
	return x.CloseSend()
}

type SRPCStreamService_AcceptStreamStream interface {
	srpc.Stream
	Send(*AcceptStreamResponse) error
	SendAndClose(*AcceptStreamResponse) error
	Recv() (*AcceptStreamRequest, error)
	RecvTo(*AcceptStreamRequest) error
}

type srpcStreamService_AcceptStreamStream struct {
	srpc.Stream
}

func (x *srpcStreamService_AcceptStreamStream) Send(m *AcceptStreamResponse) error {
	return x.MsgSend(m)
}

func (x *srpcStreamService_AcceptStreamStream) SendAndClose(m *AcceptStreamResponse) error {
	if m != nil {
		if err := x.MsgSend(m); err != nil {
			return err
		}
	}
	return x.CloseSend()
}

func (x *srpcStreamService_AcceptStreamStream) Recv() (*AcceptStreamRequest, error) {
	m := new(AcceptStreamRequest)
	if err := x.MsgRecv(m); err != nil {
		return nil, err
	}
	return m, nil
}

func (x *srpcStreamService_AcceptStreamStream) RecvTo(m *AcceptStreamRequest) error {
	return x.MsgRecv(m)
}

type SRPCStreamService_DialStreamStream interface {
	srpc.Stream
	Send(*DialStreamResponse) error
	SendAndClose(*DialStreamResponse) error
	Recv() (*DialStreamRequest, error)
	RecvTo(*DialStreamRequest) error
}

type srpcStreamService_DialStreamStream struct {
	srpc.Stream
}

func (x *srpcStreamService_DialStreamStream) Send(m *DialStreamResponse) error {
	return x.MsgSend(m)
}

func (x *srpcStreamService_DialStreamStream) SendAndClose(m *DialStreamResponse) error {
	if m != nil {
		if err := x.MsgSend(m); err != nil {
			return err
		}
	}
	return x.CloseSend()
}

func (x *srpcStreamService_DialStreamStream) Recv() (*DialStreamRequest, error) {
	m := new(DialStreamRequest)
	if err := x.MsgRecv(m); err != nil {
		return nil, err
	}
	return m, nil
}

func (x *srpcStreamService_DialStreamStream) RecvTo(m *DialStreamRequest) error {
	return x.MsgRecv(m)
}
