// Copyright 2021-2023 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// The canonical location for this file is
// https://github.com/bufbuild/connect-go/blob/main/internal/proto/connect/ping/v1/ping.proto.

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

// The connect.ping.v1 package contains an echo service designed to test the
// connect-go implementation.
package pingv1connect

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

import (
	"dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
	pingv1 "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol/internal/gen/proto/connect/ping/v1"
)

const (
	// PingServiceName is the fully-qualified name of the PingService service.
	PingServiceName = "connect.ping.v1.PingService"
)

// 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 (
	// PingServicePingProcedure is the fully-qualified name of the PingService's Ping RPC.
	PingServicePingProcedure = "/connect.ping.v1.PingService/Ping"
	// PingServiceFailProcedure is the fully-qualified name of the PingService's Fail RPC.
	PingServiceFailProcedure = "/connect.ping.v1.PingService/Fail"
	// PingServiceSumProcedure is the fully-qualified name of the PingService's Sum RPC.
	PingServiceSumProcedure = "/connect.ping.v1.PingService/Sum"
	// PingServiceCountUpProcedure is the fully-qualified name of the PingService's CountUp RPC.
	PingServiceCountUpProcedure = "/connect.ping.v1.PingService/CountUp"
	// PingServiceCumSumProcedure is the fully-qualified name of the PingService's CumSum RPC.
	PingServiceCumSumProcedure = "/connect.ping.v1.PingService/CumSum"
)

// PingServiceClient is a client for the connect.ping.v1.PingService service.
type PingServiceClient interface {
	// Ping sends a ping to the server to determine if it's reachable.
	Ping(context.Context, *triple_protocol.Request, *triple_protocol.Response) error
	// Fail always fails.
	Fail(context.Context, *triple_protocol.Request, *triple_protocol.Response) error
	// Sum calculates the sum of the numbers sent on the stream.
	Sum(context.Context) (*triple_protocol.ClientStreamForClient, error)
	// CountUp returns a stream of the numbers up to the given request.
	CountUp(context.Context, *triple_protocol.Request) (*triple_protocol.ServerStreamForClient, error)
	// CumSum determines the cumulative sum of all the numbers sent on the stream.
	CumSum(context.Context) (*triple_protocol.BidiStreamForClient, error)
}

// NewPingServiceClient constructs a client for the connect.ping.v1.PingService 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 NewPingServiceClient(httpClient triple_protocol.HTTPClient, baseURL string, opts ...triple_protocol.ClientOption) PingServiceClient {
	baseURL = strings.TrimRight(baseURL, "/")
	return &pingServiceClient{
		ping: triple_protocol.NewClient(
			httpClient,
			baseURL+PingServicePingProcedure,
			triple_protocol.WithIdempotency(triple_protocol.IdempotencyNoSideEffects),
			triple_protocol.WithClientOptions(opts...),
		),
		fail: triple_protocol.NewClient(
			httpClient,
			baseURL+PingServiceFailProcedure,
			opts...,
		),
		sum: triple_protocol.NewClient(
			httpClient,
			baseURL+PingServiceSumProcedure,
			opts...,
		),
		countUp: triple_protocol.NewClient(
			httpClient,
			baseURL+PingServiceCountUpProcedure,
			opts...,
		),
		cumSum: triple_protocol.NewClient(
			httpClient,
			baseURL+PingServiceCumSumProcedure,
			opts...,
		),
	}
}

// pingServiceClient implements PingServiceClient.
type pingServiceClient struct {
	ping    *triple_protocol.Client
	fail    *triple_protocol.Client
	sum     *triple_protocol.Client
	countUp *triple_protocol.Client
	cumSum  *triple_protocol.Client
}

// Ping calls connect.ping.v1.PingService.Ping.
// Ping(context.Context, *pingv1.PingRequest,*pingv1.PingResponse) (error)
func (c *pingServiceClient) Ping(ctx context.Context, req *triple_protocol.Request, res *triple_protocol.Response) error {
	return c.ping.CallUnary(ctx, req, res)
}

// Fail calls connect.ping.v1.PingService.Fail.
func (c *pingServiceClient) Fail(ctx context.Context, req *triple_protocol.Request, res *triple_protocol.Response) error {
	return c.fail.CallUnary(ctx, req, res)
}

// Sum calls connect.ping.v1.PingService.Sum.
func (c *pingServiceClient) Sum(ctx context.Context) (*triple_protocol.ClientStreamForClient, error) {
	return c.sum.CallClientStream(ctx)
}

// CountUp calls connect.ping.v1.PingService.CountUp.
func (c *pingServiceClient) CountUp(ctx context.Context, req *triple_protocol.Request) (*triple_protocol.ServerStreamForClient, error) {
	return c.countUp.CallServerStream(ctx, req)
}

// CumSum calls connect.ping.v1.PingService.CumSum.
func (c *pingServiceClient) CumSum(ctx context.Context) (*triple_protocol.BidiStreamForClient, error) {
	return c.cumSum.CallBidiStream(ctx)
}

// PingServiceHandler is an implementation of the connect.ping.v1.PingService service.
type PingServiceHandler interface {
	// Ping sends a ping to the server to determine if it's reachable.
	Ping(context.Context, *triple_protocol.Request) (*triple_protocol.Response, error)
	// Fail always fails.
	Fail(context.Context, *triple_protocol.Request) (*triple_protocol.Response, error)
	// Sum calculates the sum of the numbers sent on the stream.
	Sum(context.Context, *triple_protocol.ClientStream) (*triple_protocol.Response, error)
	// CountUp returns a stream of the numbers up to the given request.
	CountUp(context.Context, *triple_protocol.Request, *triple_protocol.ServerStream) error
	// CumSum determines the cumulative sum of all the numbers sent on the stream.
	CumSum(context.Context, *triple_protocol.BidiStream) error
}

// NewPingServiceHandler 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 NewPingServiceHandler(svc PingServiceHandler, opts ...triple_protocol.HandlerOption) (string, http.Handler) {
	pingServicePingHandler := triple_protocol.NewUnaryHandler(
		PingServicePingProcedure, func() any {
			return &pingv1.PingRequest{}
		},
		svc.Ping,
		triple_protocol.WithIdempotency(triple_protocol.IdempotencyNoSideEffects),
		triple_protocol.WithHandlerOptions(opts...),
	)
	pingServiceFailHandler := triple_protocol.NewUnaryHandler(
		PingServiceFailProcedure,
		func() any {
			return &pingv1.FailRequest{}
		},
		svc.Fail,
		opts...,
	)
	pingServiceSumHandler := triple_protocol.NewClientStreamHandler(
		PingServiceSumProcedure,
		svc.Sum,
		opts...,
	)
	pingServiceCountUpHandler := triple_protocol.NewServerStreamHandler(
		PingServiceCountUpProcedure, func() any {
			return &pingv1.CountUpRequest{}
		},
		svc.CountUp,
		opts...,
	)
	pingServiceCumSumHandler := triple_protocol.NewBidiStreamHandler(
		PingServiceCumSumProcedure,
		svc.CumSum,
		opts...,
	)
	return "/connect.ping.v1.PingService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.URL.Path {
		case PingServicePingProcedure:
			pingServicePingHandler.ServeHTTP(w, r)
		case PingServiceFailProcedure:
			pingServiceFailHandler.ServeHTTP(w, r)
		case PingServiceSumProcedure:
			pingServiceSumHandler.ServeHTTP(w, r)
		case PingServiceCountUpProcedure:
			pingServiceCountUpHandler.ServeHTTP(w, r)
		case PingServiceCumSumProcedure:
			pingServiceCumSumHandler.ServeHTTP(w, r)
		default:
			http.NotFound(w, r)
		}
	})
}

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

func (UnimplementedPingServiceHandler) Ping(context.Context, *triple_protocol.Request) (*triple_protocol.Response, error) {
	return nil, triple_protocol.NewError(triple_protocol.CodeUnimplemented, errors.New("connect.ping.v1.PingService.Ping is not implemented"))
}

func (UnimplementedPingServiceHandler) Fail(context.Context, *triple_protocol.Request) (*triple_protocol.Response, error) {
	return nil, triple_protocol.NewError(triple_protocol.CodeUnimplemented, errors.New("connect.ping.v1.PingService.Fail is not implemented"))
}

func (UnimplementedPingServiceHandler) Sum(context.Context, *triple_protocol.ClientStream) (*triple_protocol.Response, error) {
	return nil, triple_protocol.NewError(triple_protocol.CodeUnimplemented, errors.New("connect.ping.v1.PingService.Sum is not implemented"))
}

func (UnimplementedPingServiceHandler) CountUp(context.Context, *triple_protocol.Request, *triple_protocol.ServerStream) error {
	return triple_protocol.NewError(triple_protocol.CodeUnimplemented, errors.New("connect.ping.v1.PingService.CountUp is not implemented"))
}

func (UnimplementedPingServiceHandler) CumSum(context.Context, *triple_protocol.BidiStream) error {
	return triple_protocol.NewError(triple_protocol.CodeUnimplemented, errors.New("connect.ping.v1.PingService.CumSum is not implemented"))
}
