// Code generated by protoc-gen-srpc. DO NOT EDIT.
// protoc-gen-srpc version: v0.38.0
// source: github.com/aperturerobotics/starpc/mock/mock.proto

package e2e_mock

import (
	context "context"

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

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

	// MockRequest runs a mock unary request.
	MockRequest(ctx context.Context, in *MockMsg) (*MockMsg, error)
}

type srpcMockClient struct {
	cc        srpc.Client
	serviceID string
}

func NewSRPCMockClient(cc srpc.Client) SRPCMockClient {
	return &srpcMockClient{cc: cc, serviceID: SRPCMockServiceID}
}

func NewSRPCMockClientWithServiceID(cc srpc.Client, serviceID string) SRPCMockClient {
	if serviceID == "" {
		serviceID = SRPCMockServiceID
	}
	return &srpcMockClient{cc: cc, serviceID: serviceID}
}

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

func (c *srpcMockClient) MockRequest(ctx context.Context, in *MockMsg) (*MockMsg, error) {
	out := new(MockMsg)
	err := c.cc.ExecCall(ctx, c.serviceID, "MockRequest", in, out)
	if err != nil {
		return nil, err
	}
	return out, nil
}

type SRPCMockServer interface {
	// MockRequest runs a mock unary request.
	MockRequest(context.Context, *MockMsg) (*MockMsg, error)
}

const SRPCMockServiceID = "e2e.mock.Mock"

type SRPCMockHandler struct {
	serviceID string
	impl      SRPCMockServer
}

// NewSRPCMockHandler constructs a new RPC handler.
// serviceID: if empty, uses default: e2e.mock.Mock
func NewSRPCMockHandler(impl SRPCMockServer, serviceID string) srpc.Handler {
	if serviceID == "" {
		serviceID = SRPCMockServiceID
	}
	return &SRPCMockHandler{impl: impl, serviceID: serviceID}
}

// SRPCRegisterMock registers the implementation with the mux.
// Uses the default serviceID: e2e.mock.Mock
func SRPCRegisterMock(mux srpc.Mux, impl SRPCMockServer) error {
	return mux.Register(NewSRPCMockHandler(impl, ""))
}

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

func (SRPCMockHandler) GetMethodIDs() []string {
	return []string{
		"MockRequest",
	}
}

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

	switch methodID {
	case "MockRequest":
		return true, d.InvokeMethod_MockRequest(d.impl, strm)
	default:
		return false, nil
	}
}

func (SRPCMockHandler) InvokeMethod_MockRequest(impl SRPCMockServer, strm srpc.Stream) error {
	req := new(MockMsg)
	if err := strm.MsgRecv(req); err != nil {
		return err
	}
	out, err := impl.MockRequest(strm.Context(), req)
	if err != nil {
		return err
	}
	return strm.MsgSend(out)
}

type SRPCMock_MockRequestStream interface {
	srpc.Stream
}

type srpcMock_MockRequestStream struct {
	srpc.Stream
}
