// 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: sampleapp.proto

package sampleappconnect

import (
	"context"
	"errors"
	"net/http"
	"strings"

	"connectrpc.com/connect"

	"github.com/newrelic/go-agent/v3/integrations/nrconnect/example/sampleapp"
)

// 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 (
	// SampleApplicationName is the fully-qualified name of the SampleApplication service.
	SampleApplicationName = "SampleApplication"
)

// 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 (
	// SampleApplicationDoUnaryUnaryProcedure is the fully-qualified name of the SampleApplication's
	// DoUnaryUnary RPC.
	SampleApplicationDoUnaryUnaryProcedure = "/SampleApplication/DoUnaryUnary"
	// SampleApplicationDoUnaryStreamProcedure is the fully-qualified name of the SampleApplication's
	// DoUnaryStream RPC.
	SampleApplicationDoUnaryStreamProcedure = "/SampleApplication/DoUnaryStream"
	// SampleApplicationDoStreamUnaryProcedure is the fully-qualified name of the SampleApplication's
	// DoStreamUnary RPC.
	SampleApplicationDoStreamUnaryProcedure = "/SampleApplication/DoStreamUnary"
	// SampleApplicationDoStreamStreamProcedure is the fully-qualified name of the SampleApplication's
	// DoStreamStream RPC.
	SampleApplicationDoStreamStreamProcedure = "/SampleApplication/DoStreamStream"
)

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

// NewSampleApplicationClient constructs a client for the SampleApplication 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 NewSampleApplicationClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) SampleApplicationClient {
	baseURL = strings.TrimRight(baseURL, "/")
	sampleApplicationMethods := sampleapp.File_sampleapp_proto.Services().ByName("SampleApplication").Methods()
	return &sampleApplicationClient{
		doUnaryUnary: connect.NewClient[sampleapp.Message, sampleapp.Message](
			httpClient,
			baseURL+SampleApplicationDoUnaryUnaryProcedure,
			connect.WithSchema(sampleApplicationMethods.ByName("DoUnaryUnary")),
			connect.WithClientOptions(opts...),
		),
		doUnaryStream: connect.NewClient[sampleapp.Message, sampleapp.Message](
			httpClient,
			baseURL+SampleApplicationDoUnaryStreamProcedure,
			connect.WithSchema(sampleApplicationMethods.ByName("DoUnaryStream")),
			connect.WithClientOptions(opts...),
		),
		doStreamUnary: connect.NewClient[sampleapp.Message, sampleapp.Message](
			httpClient,
			baseURL+SampleApplicationDoStreamUnaryProcedure,
			connect.WithSchema(sampleApplicationMethods.ByName("DoStreamUnary")),
			connect.WithClientOptions(opts...),
		),
		doStreamStream: connect.NewClient[sampleapp.Message, sampleapp.Message](
			httpClient,
			baseURL+SampleApplicationDoStreamStreamProcedure,
			connect.WithSchema(sampleApplicationMethods.ByName("DoStreamStream")),
			connect.WithClientOptions(opts...),
		),
	}
}

// sampleApplicationClient implements SampleApplicationClient.
type sampleApplicationClient struct {
	doUnaryUnary   *connect.Client[sampleapp.Message, sampleapp.Message]
	doUnaryStream  *connect.Client[sampleapp.Message, sampleapp.Message]
	doStreamUnary  *connect.Client[sampleapp.Message, sampleapp.Message]
	doStreamStream *connect.Client[sampleapp.Message, sampleapp.Message]
}

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

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

// DoStreamUnary calls SampleApplication.DoStreamUnary.
func (c *sampleApplicationClient) DoStreamUnary(ctx context.Context) *connect.ClientStreamForClient[sampleapp.Message, sampleapp.Message] {
	return c.doStreamUnary.CallClientStream(ctx)
}

// DoStreamStream calls SampleApplication.DoStreamStream.
func (c *sampleApplicationClient) DoStreamStream(ctx context.Context) *connect.BidiStreamForClient[sampleapp.Message, sampleapp.Message] {
	return c.doStreamStream.CallBidiStream(ctx)
}

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

// NewSampleApplicationHandler 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 NewSampleApplicationHandler(svc SampleApplicationHandler, opts ...connect.HandlerOption) (string, http.Handler) {
	sampleApplicationMethods := sampleapp.File_sampleapp_proto.Services().ByName("SampleApplication").Methods()
	sampleApplicationDoUnaryUnaryHandler := connect.NewUnaryHandler(
		SampleApplicationDoUnaryUnaryProcedure,
		svc.DoUnaryUnary,
		connect.WithSchema(sampleApplicationMethods.ByName("DoUnaryUnary")),
		connect.WithHandlerOptions(opts...),
	)
	sampleApplicationDoUnaryStreamHandler := connect.NewServerStreamHandler(
		SampleApplicationDoUnaryStreamProcedure,
		svc.DoUnaryStream,
		connect.WithSchema(sampleApplicationMethods.ByName("DoUnaryStream")),
		connect.WithHandlerOptions(opts...),
	)
	sampleApplicationDoStreamUnaryHandler := connect.NewClientStreamHandler(
		SampleApplicationDoStreamUnaryProcedure,
		svc.DoStreamUnary,
		connect.WithSchema(sampleApplicationMethods.ByName("DoStreamUnary")),
		connect.WithHandlerOptions(opts...),
	)
	sampleApplicationDoStreamStreamHandler := connect.NewBidiStreamHandler(
		SampleApplicationDoStreamStreamProcedure,
		svc.DoStreamStream,
		connect.WithSchema(sampleApplicationMethods.ByName("DoStreamStream")),
		connect.WithHandlerOptions(opts...),
	)
	return "/SampleApplication/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.URL.Path {
		case SampleApplicationDoUnaryUnaryProcedure:
			sampleApplicationDoUnaryUnaryHandler.ServeHTTP(w, r)
		case SampleApplicationDoUnaryStreamProcedure:
			sampleApplicationDoUnaryStreamHandler.ServeHTTP(w, r)
		case SampleApplicationDoStreamUnaryProcedure:
			sampleApplicationDoStreamUnaryHandler.ServeHTTP(w, r)
		case SampleApplicationDoStreamStreamProcedure:
			sampleApplicationDoStreamStreamHandler.ServeHTTP(w, r)
		default:
			http.NotFound(w, r)
		}
	})
}

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

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

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

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

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