// Code generated by protoc-gen-connect-go. DO NOT EDIT.
//
// Source: xyz/block/ftl/query/v1/query.proto

package querypbconnect

import (
	connect "connectrpc.com/connect"
	context "context"
	errors "errors"
	v11 "github.com/block/ftl/backend/protos/xyz/block/ftl/query/v1"
	v1 "github.com/block/ftl/backend/protos/xyz/block/ftl/v1"
	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 (
	// QueryServiceName is the fully-qualified name of the QueryService service.
	QueryServiceName = "xyz.block.ftl.query.v1.QueryService"
)

// 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 (
	// QueryServicePingProcedure is the fully-qualified name of the QueryService's Ping RPC.
	QueryServicePingProcedure = "/xyz.block.ftl.query.v1.QueryService/Ping"
	// QueryServiceBeginTransactionProcedure is the fully-qualified name of the QueryService's
	// BeginTransaction RPC.
	QueryServiceBeginTransactionProcedure = "/xyz.block.ftl.query.v1.QueryService/BeginTransaction"
	// QueryServiceCommitTransactionProcedure is the fully-qualified name of the QueryService's
	// CommitTransaction RPC.
	QueryServiceCommitTransactionProcedure = "/xyz.block.ftl.query.v1.QueryService/CommitTransaction"
	// QueryServiceRollbackTransactionProcedure is the fully-qualified name of the QueryService's
	// RollbackTransaction RPC.
	QueryServiceRollbackTransactionProcedure = "/xyz.block.ftl.query.v1.QueryService/RollbackTransaction"
	// QueryServiceExecuteQueryProcedure is the fully-qualified name of the QueryService's ExecuteQuery
	// RPC.
	QueryServiceExecuteQueryProcedure = "/xyz.block.ftl.query.v1.QueryService/ExecuteQuery"
)

// QueryServiceClient is a client for the xyz.block.ftl.query.v1.QueryService service.
type QueryServiceClient interface {
	// Ping service for readiness
	Ping(context.Context, *connect.Request[v1.PingRequest]) (*connect.Response[v1.PingResponse], error)
	// Begins a new transaction and returns a transaction ID.
	BeginTransaction(context.Context, *connect.Request[v11.BeginTransactionRequest]) (*connect.Response[v11.BeginTransactionResponse], error)
	// Commits a transaction.
	CommitTransaction(context.Context, *connect.Request[v11.CommitTransactionRequest]) (*connect.Response[v11.CommitTransactionResponse], error)
	// Rolls back a transaction.
	RollbackTransaction(context.Context, *connect.Request[v11.RollbackTransactionRequest]) (*connect.Response[v11.RollbackTransactionResponse], error)
	// Executes a raw SQL query, optionally within a transaction.
	ExecuteQuery(context.Context, *connect.Request[v11.ExecuteQueryRequest]) (*connect.ServerStreamForClient[v11.ExecuteQueryResponse], error)
}

// NewQueryServiceClient constructs a client for the xyz.block.ftl.query.v1.QueryService 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 NewQueryServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) QueryServiceClient {
	baseURL = strings.TrimRight(baseURL, "/")
	queryServiceMethods := v11.File_xyz_block_ftl_query_v1_query_proto.Services().ByName("QueryService").Methods()
	return &queryServiceClient{
		ping: connect.NewClient[v1.PingRequest, v1.PingResponse](
			httpClient,
			baseURL+QueryServicePingProcedure,
			connect.WithSchema(queryServiceMethods.ByName("Ping")),
			connect.WithIdempotency(connect.IdempotencyNoSideEffects),
			connect.WithClientOptions(opts...),
		),
		beginTransaction: connect.NewClient[v11.BeginTransactionRequest, v11.BeginTransactionResponse](
			httpClient,
			baseURL+QueryServiceBeginTransactionProcedure,
			connect.WithSchema(queryServiceMethods.ByName("BeginTransaction")),
			connect.WithClientOptions(opts...),
		),
		commitTransaction: connect.NewClient[v11.CommitTransactionRequest, v11.CommitTransactionResponse](
			httpClient,
			baseURL+QueryServiceCommitTransactionProcedure,
			connect.WithSchema(queryServiceMethods.ByName("CommitTransaction")),
			connect.WithClientOptions(opts...),
		),
		rollbackTransaction: connect.NewClient[v11.RollbackTransactionRequest, v11.RollbackTransactionResponse](
			httpClient,
			baseURL+QueryServiceRollbackTransactionProcedure,
			connect.WithSchema(queryServiceMethods.ByName("RollbackTransaction")),
			connect.WithClientOptions(opts...),
		),
		executeQuery: connect.NewClient[v11.ExecuteQueryRequest, v11.ExecuteQueryResponse](
			httpClient,
			baseURL+QueryServiceExecuteQueryProcedure,
			connect.WithSchema(queryServiceMethods.ByName("ExecuteQuery")),
			connect.WithClientOptions(opts...),
		),
	}
}

// queryServiceClient implements QueryServiceClient.
type queryServiceClient struct {
	ping                *connect.Client[v1.PingRequest, v1.PingResponse]
	beginTransaction    *connect.Client[v11.BeginTransactionRequest, v11.BeginTransactionResponse]
	commitTransaction   *connect.Client[v11.CommitTransactionRequest, v11.CommitTransactionResponse]
	rollbackTransaction *connect.Client[v11.RollbackTransactionRequest, v11.RollbackTransactionResponse]
	executeQuery        *connect.Client[v11.ExecuteQueryRequest, v11.ExecuteQueryResponse]
}

// Ping calls xyz.block.ftl.query.v1.QueryService.Ping.
func (c *queryServiceClient) Ping(ctx context.Context, req *connect.Request[v1.PingRequest]) (*connect.Response[v1.PingResponse], error) {
	return c.ping.CallUnary(ctx, req)
}

// BeginTransaction calls xyz.block.ftl.query.v1.QueryService.BeginTransaction.
func (c *queryServiceClient) BeginTransaction(ctx context.Context, req *connect.Request[v11.BeginTransactionRequest]) (*connect.Response[v11.BeginTransactionResponse], error) {
	return c.beginTransaction.CallUnary(ctx, req)
}

// CommitTransaction calls xyz.block.ftl.query.v1.QueryService.CommitTransaction.
func (c *queryServiceClient) CommitTransaction(ctx context.Context, req *connect.Request[v11.CommitTransactionRequest]) (*connect.Response[v11.CommitTransactionResponse], error) {
	return c.commitTransaction.CallUnary(ctx, req)
}

// RollbackTransaction calls xyz.block.ftl.query.v1.QueryService.RollbackTransaction.
func (c *queryServiceClient) RollbackTransaction(ctx context.Context, req *connect.Request[v11.RollbackTransactionRequest]) (*connect.Response[v11.RollbackTransactionResponse], error) {
	return c.rollbackTransaction.CallUnary(ctx, req)
}

// ExecuteQuery calls xyz.block.ftl.query.v1.QueryService.ExecuteQuery.
func (c *queryServiceClient) ExecuteQuery(ctx context.Context, req *connect.Request[v11.ExecuteQueryRequest]) (*connect.ServerStreamForClient[v11.ExecuteQueryResponse], error) {
	return c.executeQuery.CallServerStream(ctx, req)
}

// QueryServiceHandler is an implementation of the xyz.block.ftl.query.v1.QueryService service.
type QueryServiceHandler interface {
	// Ping service for readiness
	Ping(context.Context, *connect.Request[v1.PingRequest]) (*connect.Response[v1.PingResponse], error)
	// Begins a new transaction and returns a transaction ID.
	BeginTransaction(context.Context, *connect.Request[v11.BeginTransactionRequest]) (*connect.Response[v11.BeginTransactionResponse], error)
	// Commits a transaction.
	CommitTransaction(context.Context, *connect.Request[v11.CommitTransactionRequest]) (*connect.Response[v11.CommitTransactionResponse], error)
	// Rolls back a transaction.
	RollbackTransaction(context.Context, *connect.Request[v11.RollbackTransactionRequest]) (*connect.Response[v11.RollbackTransactionResponse], error)
	// Executes a raw SQL query, optionally within a transaction.
	ExecuteQuery(context.Context, *connect.Request[v11.ExecuteQueryRequest], *connect.ServerStream[v11.ExecuteQueryResponse]) error
}

// NewQueryServiceHandler 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 NewQueryServiceHandler(svc QueryServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
	queryServiceMethods := v11.File_xyz_block_ftl_query_v1_query_proto.Services().ByName("QueryService").Methods()
	queryServicePingHandler := connect.NewUnaryHandler(
		QueryServicePingProcedure,
		svc.Ping,
		connect.WithSchema(queryServiceMethods.ByName("Ping")),
		connect.WithIdempotency(connect.IdempotencyNoSideEffects),
		connect.WithHandlerOptions(opts...),
	)
	queryServiceBeginTransactionHandler := connect.NewUnaryHandler(
		QueryServiceBeginTransactionProcedure,
		svc.BeginTransaction,
		connect.WithSchema(queryServiceMethods.ByName("BeginTransaction")),
		connect.WithHandlerOptions(opts...),
	)
	queryServiceCommitTransactionHandler := connect.NewUnaryHandler(
		QueryServiceCommitTransactionProcedure,
		svc.CommitTransaction,
		connect.WithSchema(queryServiceMethods.ByName("CommitTransaction")),
		connect.WithHandlerOptions(opts...),
	)
	queryServiceRollbackTransactionHandler := connect.NewUnaryHandler(
		QueryServiceRollbackTransactionProcedure,
		svc.RollbackTransaction,
		connect.WithSchema(queryServiceMethods.ByName("RollbackTransaction")),
		connect.WithHandlerOptions(opts...),
	)
	queryServiceExecuteQueryHandler := connect.NewServerStreamHandler(
		QueryServiceExecuteQueryProcedure,
		svc.ExecuteQuery,
		connect.WithSchema(queryServiceMethods.ByName("ExecuteQuery")),
		connect.WithHandlerOptions(opts...),
	)
	return "/xyz.block.ftl.query.v1.QueryService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.URL.Path {
		case QueryServicePingProcedure:
			queryServicePingHandler.ServeHTTP(w, r)
		case QueryServiceBeginTransactionProcedure:
			queryServiceBeginTransactionHandler.ServeHTTP(w, r)
		case QueryServiceCommitTransactionProcedure:
			queryServiceCommitTransactionHandler.ServeHTTP(w, r)
		case QueryServiceRollbackTransactionProcedure:
			queryServiceRollbackTransactionHandler.ServeHTTP(w, r)
		case QueryServiceExecuteQueryProcedure:
			queryServiceExecuteQueryHandler.ServeHTTP(w, r)
		default:
			http.NotFound(w, r)
		}
	})
}

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

func (UnimplementedQueryServiceHandler) Ping(context.Context, *connect.Request[v1.PingRequest]) (*connect.Response[v1.PingResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("xyz.block.ftl.query.v1.QueryService.Ping is not implemented"))
}

func (UnimplementedQueryServiceHandler) BeginTransaction(context.Context, *connect.Request[v11.BeginTransactionRequest]) (*connect.Response[v11.BeginTransactionResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("xyz.block.ftl.query.v1.QueryService.BeginTransaction is not implemented"))
}

func (UnimplementedQueryServiceHandler) CommitTransaction(context.Context, *connect.Request[v11.CommitTransactionRequest]) (*connect.Response[v11.CommitTransactionResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("xyz.block.ftl.query.v1.QueryService.CommitTransaction is not implemented"))
}

func (UnimplementedQueryServiceHandler) RollbackTransaction(context.Context, *connect.Request[v11.RollbackTransactionRequest]) (*connect.Response[v11.RollbackTransactionResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("xyz.block.ftl.query.v1.QueryService.RollbackTransaction is not implemented"))
}

func (UnimplementedQueryServiceHandler) ExecuteQuery(context.Context, *connect.Request[v11.ExecuteQueryRequest], *connect.ServerStream[v11.ExecuteQueryResponse]) error {
	return connect.NewError(connect.CodeUnimplemented, errors.New("xyz.block.ftl.query.v1.QueryService.ExecuteQuery is not implemented"))
}
