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

package tokensv1connect

import (
	connect "connectrpc.com/connect"
	context "context"
	errors "errors"
	v1 "github.com/tetrateio/agentrouter-go/genapi/api/tars/tokens/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 (
	// TokensServiceName is the fully-qualified name of the TokensService service.
	TokensServiceName = "tars.tokens.v1.TokensService"
)

// 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 (
	// TokensServiceGetRevocationListProcedure is the fully-qualified name of the TokensService's
	// GetRevocationList RPC.
	TokensServiceGetRevocationListProcedure = "/tars.tokens.v1.TokensService/GetRevocationList"
	// TokensServiceUpdateLastUsedProcedure is the fully-qualified name of the TokensService's
	// UpdateLastUsed RPC.
	TokensServiceUpdateLastUsedProcedure = "/tars.tokens.v1.TokensService/UpdateLastUsed"
)

// TokensServiceClient is a client for the tars.tokens.v1.TokensService service.
type TokensServiceClient interface {
	// GetRevocationList returns a list of revoked token JTIs.
	// This is used by dataplane to cache and check token revocations locally.
	GetRevocationList(context.Context, *connect.Request[v1.GetRevocationListRequest]) (*connect.Response[v1.GetRevocationListResponse], error)
	// UpdateLastUsed updates the last used timestamp for a token.
	// Called by dataplane when a token is used for authentication.
	UpdateLastUsed(context.Context, *connect.Request[v1.UpdateLastUsedRequest]) (*connect.Response[v1.UpdateLastUsedResponse], error)
}

// NewTokensServiceClient constructs a client for the tars.tokens.v1.TokensService 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 NewTokensServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TokensServiceClient {
	baseURL = strings.TrimRight(baseURL, "/")
	tokensServiceMethods := v1.File_tars_tokens_v1_tokens_proto.Services().ByName("TokensService").Methods()
	return &tokensServiceClient{
		getRevocationList: connect.NewClient[v1.GetRevocationListRequest, v1.GetRevocationListResponse](
			httpClient,
			baseURL+TokensServiceGetRevocationListProcedure,
			connect.WithSchema(tokensServiceMethods.ByName("GetRevocationList")),
			connect.WithClientOptions(opts...),
		),
		updateLastUsed: connect.NewClient[v1.UpdateLastUsedRequest, v1.UpdateLastUsedResponse](
			httpClient,
			baseURL+TokensServiceUpdateLastUsedProcedure,
			connect.WithSchema(tokensServiceMethods.ByName("UpdateLastUsed")),
			connect.WithClientOptions(opts...),
		),
	}
}

// tokensServiceClient implements TokensServiceClient.
type tokensServiceClient struct {
	getRevocationList *connect.Client[v1.GetRevocationListRequest, v1.GetRevocationListResponse]
	updateLastUsed    *connect.Client[v1.UpdateLastUsedRequest, v1.UpdateLastUsedResponse]
}

// GetRevocationList calls tars.tokens.v1.TokensService.GetRevocationList.
func (c *tokensServiceClient) GetRevocationList(ctx context.Context, req *connect.Request[v1.GetRevocationListRequest]) (*connect.Response[v1.GetRevocationListResponse], error) {
	return c.getRevocationList.CallUnary(ctx, req)
}

// UpdateLastUsed calls tars.tokens.v1.TokensService.UpdateLastUsed.
func (c *tokensServiceClient) UpdateLastUsed(ctx context.Context, req *connect.Request[v1.UpdateLastUsedRequest]) (*connect.Response[v1.UpdateLastUsedResponse], error) {
	return c.updateLastUsed.CallUnary(ctx, req)
}

// TokensServiceHandler is an implementation of the tars.tokens.v1.TokensService service.
type TokensServiceHandler interface {
	// GetRevocationList returns a list of revoked token JTIs.
	// This is used by dataplane to cache and check token revocations locally.
	GetRevocationList(context.Context, *connect.Request[v1.GetRevocationListRequest]) (*connect.Response[v1.GetRevocationListResponse], error)
	// UpdateLastUsed updates the last used timestamp for a token.
	// Called by dataplane when a token is used for authentication.
	UpdateLastUsed(context.Context, *connect.Request[v1.UpdateLastUsedRequest]) (*connect.Response[v1.UpdateLastUsedResponse], error)
}

// NewTokensServiceHandler 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 NewTokensServiceHandler(svc TokensServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
	tokensServiceMethods := v1.File_tars_tokens_v1_tokens_proto.Services().ByName("TokensService").Methods()
	tokensServiceGetRevocationListHandler := connect.NewUnaryHandler(
		TokensServiceGetRevocationListProcedure,
		svc.GetRevocationList,
		connect.WithSchema(tokensServiceMethods.ByName("GetRevocationList")),
		connect.WithHandlerOptions(opts...),
	)
	tokensServiceUpdateLastUsedHandler := connect.NewUnaryHandler(
		TokensServiceUpdateLastUsedProcedure,
		svc.UpdateLastUsed,
		connect.WithSchema(tokensServiceMethods.ByName("UpdateLastUsed")),
		connect.WithHandlerOptions(opts...),
	)
	return "/tars.tokens.v1.TokensService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.URL.Path {
		case TokensServiceGetRevocationListProcedure:
			tokensServiceGetRevocationListHandler.ServeHTTP(w, r)
		case TokensServiceUpdateLastUsedProcedure:
			tokensServiceUpdateLastUsedHandler.ServeHTTP(w, r)
		default:
			http.NotFound(w, r)
		}
	})
}

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

func (UnimplementedTokensServiceHandler) GetRevocationList(context.Context, *connect.Request[v1.GetRevocationListRequest]) (*connect.Response[v1.GetRevocationListResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.tokens.v1.TokensService.GetRevocationList is not implemented"))
}

func (UnimplementedTokensServiceHandler) UpdateLastUsed(context.Context, *connect.Request[v1.UpdateLastUsedRequest]) (*connect.Response[v1.UpdateLastUsedResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.tokens.v1.TokensService.UpdateLastUsed is not implemented"))
}
