// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

// Code generated by protoc-gen-connect-go. DO NOT EDIT.
//
// Source: testapp.proto

package testappconnect

import (
	connect "connectrpc.com/connect"
	context "context"
	errors "errors"
	testapp "github.com/newrelic/go-agent/v3/integrations/nrconnect/testapp"
	http "net/http"
	strings "strings"
)

// This is a compile-time assertion to ensure that this generated file and the connect package are
// compatible. If you get a compiler error that this constant is not defined, this code was
// generated with a version of connect newer than the one compiled into your binary. You can fix the
// problem by either regenerating this code with an older version of connect or updating the connect
// version compiled into your binary.
const _ = connect.IsAtLeastVersion1_13_0

const (
	// TestApplicationName is the fully-qualified name of the TestApplication service.
	TestApplicationName = "TestApplication"
)

// These constants are the fully-qualified names of the RPCs defined in this package. They're
// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route.
//
// Note that these are different from the fully-qualified method names used by
// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
// period.
const (
	// TestApplicationDoUnaryUnaryProcedure is the fully-qualified name of the TestApplication's
	// DoUnaryUnary RPC.
	TestApplicationDoUnaryUnaryProcedure = "/TestApplication/DoUnaryUnary"
	// TestApplicationDoUnaryStreamProcedure is the fully-qualified name of the TestApplication's
	// DoUnaryStream RPC.
	TestApplicationDoUnaryStreamProcedure = "/TestApplication/DoUnaryStream"
	// TestApplicationDoStreamUnaryProcedure is the fully-qualified name of the TestApplication's
	// DoStreamUnary RPC.
	TestApplicationDoStreamUnaryProcedure = "/TestApplication/DoStreamUnary"
	// TestApplicationDoStreamStreamProcedure is the fully-qualified name of the TestApplication's
	// DoStreamStream RPC.
	TestApplicationDoStreamStreamProcedure = "/TestApplication/DoStreamStream"
	// TestApplicationDoUnaryUnaryErrorProcedure is the fully-qualified name of the TestApplication's
	// DoUnaryUnaryError RPC.
	TestApplicationDoUnaryUnaryErrorProcedure = "/TestApplication/DoUnaryUnaryError"
	// TestApplicationDoUnaryStreamErrorProcedure is the fully-qualified name of the TestApplication's
	// DoUnaryStreamError RPC.
	TestApplicationDoUnaryStreamErrorProcedure = "/TestApplication/DoUnaryStreamError"
)

// TestApplicationClient is a client for the TestApplication service.
type TestApplicationClient interface {
	DoUnaryUnary(context.Context, *connect.Request[testapp.Message]) (*connect.Response[testapp.Message], error)
	DoUnaryStream(context.Context, *connect.Request[testapp.Message]) (*connect.ServerStreamForClient[testapp.Message], error)
	DoStreamUnary(context.Context) *connect.ClientStreamForClient[testapp.Message, testapp.Message]
	DoStreamStream(context.Context) *connect.BidiStreamForClient[testapp.Message, testapp.Message]
	DoUnaryUnaryError(context.Context, *connect.Request[testapp.Message]) (*connect.Response[testapp.Message], error)
	DoUnaryStreamError(context.Context, *connect.Request[testapp.Message]) (*connect.ServerStreamForClient[testapp.Message], error)
}

// NewTestApplicationClient constructs a client for the TestApplication service. By default, it uses
// the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, and sends
// uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or
// connect.WithGRPCWeb() options.
//
// The URL supplied here should be the base URL for the Connect or gRPC server (for example,
// http://api.acme.com or https://acme.com/grpc).
func NewTestApplicationClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TestApplicationClient {
	baseURL = strings.TrimRight(baseURL, "/")
	testApplicationMethods := testapp.File_testapp_proto.Services().ByName("TestApplication").Methods()
	return &testApplicationClient{
		doUnaryUnary: connect.NewClient[testapp.Message, testapp.Message](
			httpClient,
			baseURL+TestApplicationDoUnaryUnaryProcedure,
			connect.WithSchema(testApplicationMethods.ByName("DoUnaryUnary")),
			connect.WithClientOptions(opts...),
		),
		doUnaryStream: connect.NewClient[testapp.Message, testapp.Message](
			httpClient,
			baseURL+TestApplicationDoUnaryStreamProcedure,
			connect.WithSchema(testApplicationMethods.ByName("DoUnaryStream")),
			connect.WithClientOptions(opts...),
		),
		doStreamUnary: connect.NewClient[testapp.Message, testapp.Message](
			httpClient,
			baseURL+TestApplicationDoStreamUnaryProcedure,
			connect.WithSchema(testApplicationMethods.ByName("DoStreamUnary")),
			connect.WithClientOptions(opts...),
		),
		doStreamStream: connect.NewClient[testapp.Message, testapp.Message](
			httpClient,
			baseURL+TestApplicationDoStreamStreamProcedure,
			connect.WithSchema(testApplicationMethods.ByName("DoStreamStream")),
			connect.WithClientOptions(opts...),
		),
		doUnaryUnaryError: connect.NewClient[testapp.Message, testapp.Message](
			httpClient,
			baseURL+TestApplicationDoUnaryUnaryErrorProcedure,
			connect.WithSchema(testApplicationMethods.ByName("DoUnaryUnaryError")),
			connect.WithClientOptions(opts...),
		),
		doUnaryStreamError: connect.NewClient[testapp.Message, testapp.Message](
			httpClient,
			baseURL+TestApplicationDoUnaryStreamErrorProcedure,
			connect.WithSchema(testApplicationMethods.ByName("DoUnaryStreamError")),
			connect.WithClientOptions(opts...),
		),
	}
}

// testApplicationClient implements TestApplicationClient.
type testApplicationClient struct {
	doUnaryUnary       *connect.Client[testapp.Message, testapp.Message]
	doUnaryStream      *connect.Client[testapp.Message, testapp.Message]
	doStreamUnary      *connect.Client[testapp.Message, testapp.Message]
	doStreamStream     *connect.Client[testapp.Message, testapp.Message]
	doUnaryUnaryError  *connect.Client[testapp.Message, testapp.Message]
	doUnaryStreamError *connect.Client[testapp.Message, testapp.Message]
}

// DoUnaryUnary calls TestApplication.DoUnaryUnary.
func (c *testApplicationClient) DoUnaryUnary(ctx context.Context, req *connect.Request[testapp.Message]) (*connect.Response[testapp.Message], error) {
	return c.doUnaryUnary.CallUnary(ctx, req)
}

// DoUnaryStream calls TestApplication.DoUnaryStream.
func (c *testApplicationClient) DoUnaryStream(ctx context.Context, req *connect.Request[testapp.Message]) (*connect.ServerStreamForClient[testapp.Message], error) {
	return c.doUnaryStream.CallServerStream(ctx, req)
}

// DoStreamUnary calls TestApplication.DoStreamUnary.
func (c *testApplicationClient) DoStreamUnary(ctx context.Context) *connect.ClientStreamForClient[testapp.Message, testapp.Message] {
	return c.doStreamUnary.CallClientStream(ctx)
}

// DoStreamStream calls TestApplication.DoStreamStream.
func (c *testApplicationClient) DoStreamStream(ctx context.Context) *connect.BidiStreamForClient[testapp.Message, testapp.Message] {
	return c.doStreamStream.CallBidiStream(ctx)
}

// DoUnaryUnaryError calls TestApplication.DoUnaryUnaryError.
func (c *testApplicationClient) DoUnaryUnaryError(ctx context.Context, req *connect.Request[testapp.Message]) (*connect.Response[testapp.Message], error) {
	return c.doUnaryUnaryError.CallUnary(ctx, req)
}

// DoUnaryStreamError calls TestApplication.DoUnaryStreamError.
func (c *testApplicationClient) DoUnaryStreamError(ctx context.Context, req *connect.Request[testapp.Message]) (*connect.ServerStreamForClient[testapp.Message], error) {
	return c.doUnaryStreamError.CallServerStream(ctx, req)
}

// TestApplicationHandler is an implementation of the TestApplication service.
type TestApplicationHandler interface {
	DoUnaryUnary(context.Context, *connect.Request[testapp.Message]) (*connect.Response[testapp.Message], error)
	DoUnaryStream(context.Context, *connect.Request[testapp.Message], *connect.ServerStream[testapp.Message]) error
	DoStreamUnary(context.Context, *connect.ClientStream[testapp.Message]) (*connect.Response[testapp.Message], error)
	DoStreamStream(context.Context, *connect.BidiStream[testapp.Message, testapp.Message]) error
	DoUnaryUnaryError(context.Context, *connect.Request[testapp.Message]) (*connect.Response[testapp.Message], error)
	DoUnaryStreamError(context.Context, *connect.Request[testapp.Message], *connect.ServerStream[testapp.Message]) error
}

// NewTestApplicationHandler builds an HTTP handler from the service implementation. It returns the
// path on which to mount the handler and the handler itself.
//
// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf
// and JSON codecs. They also support gzip compression.
func NewTestApplicationHandler(svc TestApplicationHandler, opts ...connect.HandlerOption) (string, http.Handler) {
	testApplicationMethods := testapp.File_testapp_proto.Services().ByName("TestApplication").Methods()
	testApplicationDoUnaryUnaryHandler := connect.NewUnaryHandler(
		TestApplicationDoUnaryUnaryProcedure,
		svc.DoUnaryUnary,
		connect.WithSchema(testApplicationMethods.ByName("DoUnaryUnary")),
		connect.WithHandlerOptions(opts...),
	)
	testApplicationDoUnaryStreamHandler := connect.NewServerStreamHandler(
		TestApplicationDoUnaryStreamProcedure,
		svc.DoUnaryStream,
		connect.WithSchema(testApplicationMethods.ByName("DoUnaryStream")),
		connect.WithHandlerOptions(opts...),
	)
	testApplicationDoStreamUnaryHandler := connect.NewClientStreamHandler(
		TestApplicationDoStreamUnaryProcedure,
		svc.DoStreamUnary,
		connect.WithSchema(testApplicationMethods.ByName("DoStreamUnary")),
		connect.WithHandlerOptions(opts...),
	)
	testApplicationDoStreamStreamHandler := connect.NewBidiStreamHandler(
		TestApplicationDoStreamStreamProcedure,
		svc.DoStreamStream,
		connect.WithSchema(testApplicationMethods.ByName("DoStreamStream")),
		connect.WithHandlerOptions(opts...),
	)
	testApplicationDoUnaryUnaryErrorHandler := connect.NewUnaryHandler(
		TestApplicationDoUnaryUnaryErrorProcedure,
		svc.DoUnaryUnaryError,
		connect.WithSchema(testApplicationMethods.ByName("DoUnaryUnaryError")),
		connect.WithHandlerOptions(opts...),
	)
	testApplicationDoUnaryStreamErrorHandler := connect.NewServerStreamHandler(
		TestApplicationDoUnaryStreamErrorProcedure,
		svc.DoUnaryStreamError,
		connect.WithSchema(testApplicationMethods.ByName("DoUnaryStreamError")),
		connect.WithHandlerOptions(opts...),
	)
	return "/TestApplication/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.URL.Path {
		case TestApplicationDoUnaryUnaryProcedure:
			testApplicationDoUnaryUnaryHandler.ServeHTTP(w, r)
		case TestApplicationDoUnaryStreamProcedure:
			testApplicationDoUnaryStreamHandler.ServeHTTP(w, r)
		case TestApplicationDoStreamUnaryProcedure:
			testApplicationDoStreamUnaryHandler.ServeHTTP(w, r)
		case TestApplicationDoStreamStreamProcedure:
			testApplicationDoStreamStreamHandler.ServeHTTP(w, r)
		case TestApplicationDoUnaryUnaryErrorProcedure:
			testApplicationDoUnaryUnaryErrorHandler.ServeHTTP(w, r)
		case TestApplicationDoUnaryStreamErrorProcedure:
			testApplicationDoUnaryStreamErrorHandler.ServeHTTP(w, r)
		default:
			http.NotFound(w, r)
		}
	})
}

// UnimplementedTestApplicationHandler returns CodeUnimplemented from all methods.
type UnimplementedTestApplicationHandler struct{}

func (UnimplementedTestApplicationHandler) DoUnaryUnary(context.Context, *connect.Request[testapp.Message]) (*connect.Response[testapp.Message], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("TestApplication.DoUnaryUnary is not implemented"))
}

func (UnimplementedTestApplicationHandler) DoUnaryStream(context.Context, *connect.Request[testapp.Message], *connect.ServerStream[testapp.Message]) error {
	return connect.NewError(connect.CodeUnimplemented, errors.New("TestApplication.DoUnaryStream is not implemented"))
}

func (UnimplementedTestApplicationHandler) DoStreamUnary(context.Context, *connect.ClientStream[testapp.Message]) (*connect.Response[testapp.Message], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("TestApplication.DoStreamUnary is not implemented"))
}

func (UnimplementedTestApplicationHandler) DoStreamStream(context.Context, *connect.BidiStream[testapp.Message, testapp.Message]) error {
	return connect.NewError(connect.CodeUnimplemented, errors.New("TestApplication.DoStreamStream is not implemented"))
}

func (UnimplementedTestApplicationHandler) DoUnaryUnaryError(context.Context, *connect.Request[testapp.Message]) (*connect.Response[testapp.Message], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("TestApplication.DoUnaryUnaryError is not implemented"))
}

func (UnimplementedTestApplicationHandler) DoUnaryStreamError(context.Context, *connect.Request[testapp.Message], *connect.ServerStream[testapp.Message]) error {
	return connect.NewError(connect.CodeUnimplemented, errors.New("TestApplication.DoUnaryStreamError is not implemented"))
}
