// AiKeysService -- BYOK provider key registration and inference-side
// fetch.
//
// Customers register their own provider key (e.g. an OpenAI API key);
// the inference handler (and, in milestone C, the dataplane) fetches it
// over the internal subdomain and uses the customer's key when
// forwarding to the provider.
//
// Plan reference: B2 in check-ia-and-plan-optimized-cook.md.

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

package aikeysv1connect

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

// 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 (
	// AiKeysServiceRegisterProcedure is the fully-qualified name of the AiKeysService's Register RPC.
	AiKeysServiceRegisterProcedure = "/tars.aikeys.v1.AiKeysService/Register"
	// AiKeysServiceGetProcedure is the fully-qualified name of the AiKeysService's Get RPC.
	AiKeysServiceGetProcedure = "/tars.aikeys.v1.AiKeysService/Get"
	// AiKeysServiceListProcedure is the fully-qualified name of the AiKeysService's List RPC.
	AiKeysServiceListProcedure = "/tars.aikeys.v1.AiKeysService/List"
	// AiKeysServiceRevokeProcedure is the fully-qualified name of the AiKeysService's Revoke RPC.
	AiKeysServiceRevokeProcedure = "/tars.aikeys.v1.AiKeysService/Revoke"
	// AiKeysServiceFetchProcedure is the fully-qualified name of the AiKeysService's Fetch RPC.
	AiKeysServiceFetchProcedure = "/tars.aikeys.v1.AiKeysService/Fetch"
)

// AiKeysServiceClient is a client for the tars.aikeys.v1.AiKeysService service.
type AiKeysServiceClient interface {
	// Register encrypts and stores a provider API key under a project.
	// After this call, inference requests routed to the matching provider
	// for this project will use this key.
	//
	// Scope: account-tier so any project member can register their OWN
	// user-scoped key (user_scope=true). Registering a PROJECT-level key
	// (user_scope=false) additionally requires the caller to be the
	// project's owner -- enforced in-handler against project_members.
	Register(context.Context, *connect.Request[v1.RegisterRequest]) (*connect.Response[v1.RegisterResponse], error)
	// Get returns the metadata record for a single BYOK key. Never returns
	// the plaintext.
	//
	// Scope: account-tier. Any project member may read keys in the project
	// (project-level and the caller's own user-scoped keys); membership is
	// enforced in-handler.
	Get(context.Context, *connect.Request[v1.GetRequest]) (*connect.Response[v1.GetResponse], error)
	// List lists BYOK keys registered under a project. Returns metadata
	// only -- id, provider, name, display_suffix, creation timestamp, and
	// revocation timestamp if revoked. The result includes the project's
	// shared keys plus the caller's own user-scoped keys (other users'
	// user-scoped keys are not returned).
	//
	// Scope: account-tier; membership is enforced in-handler.
	List(context.Context, *connect.Request[v1.ListRequest]) (*connect.Response[v1.ListResponse], error)
	// Revoke marks the key revoked; subsequent Fetches return
	// permission_denied. Inflight cached keys on dataplanes invalidate
	// within sub-second via the revocation channel (milestone C).
	//
	// Scope: account-tier so a member can revoke their OWN user-scoped key.
	// Revoking a PROJECT-level key additionally requires project ownership
	// (enforced in-handler); a member may never revoke another user's
	// user-scoped key.
	Revoke(context.Context, *connect.Request[v1.RevokeRequest]) (*connect.Response[v1.RevokeResponse], error)
	// Fetch is the internal-only RPC the inference handler / dataplane
	// calls on the hot path. Returns the plaintext provider key.
	Fetch(context.Context, *connect.Request[v1.FetchRequest]) (*connect.Response[v1.FetchResponse], error)
}

// NewAiKeysServiceClient constructs a client for the tars.aikeys.v1.AiKeysService 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 NewAiKeysServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) AiKeysServiceClient {
	baseURL = strings.TrimRight(baseURL, "/")
	aiKeysServiceMethods := v1.File_tars_aikeys_v1_aikeys_proto.Services().ByName("AiKeysService").Methods()
	return &aiKeysServiceClient{
		register: connect.NewClient[v1.RegisterRequest, v1.RegisterResponse](
			httpClient,
			baseURL+AiKeysServiceRegisterProcedure,
			connect.WithSchema(aiKeysServiceMethods.ByName("Register")),
			connect.WithClientOptions(opts...),
		),
		get: connect.NewClient[v1.GetRequest, v1.GetResponse](
			httpClient,
			baseURL+AiKeysServiceGetProcedure,
			connect.WithSchema(aiKeysServiceMethods.ByName("Get")),
			connect.WithIdempotency(connect.IdempotencyNoSideEffects),
			connect.WithClientOptions(opts...),
		),
		list: connect.NewClient[v1.ListRequest, v1.ListResponse](
			httpClient,
			baseURL+AiKeysServiceListProcedure,
			connect.WithSchema(aiKeysServiceMethods.ByName("List")),
			connect.WithIdempotency(connect.IdempotencyNoSideEffects),
			connect.WithClientOptions(opts...),
		),
		revoke: connect.NewClient[v1.RevokeRequest, v1.RevokeResponse](
			httpClient,
			baseURL+AiKeysServiceRevokeProcedure,
			connect.WithSchema(aiKeysServiceMethods.ByName("Revoke")),
			connect.WithClientOptions(opts...),
		),
		fetch: connect.NewClient[v1.FetchRequest, v1.FetchResponse](
			httpClient,
			baseURL+AiKeysServiceFetchProcedure,
			connect.WithSchema(aiKeysServiceMethods.ByName("Fetch")),
			connect.WithIdempotency(connect.IdempotencyNoSideEffects),
			connect.WithClientOptions(opts...),
		),
	}
}

// aiKeysServiceClient implements AiKeysServiceClient.
type aiKeysServiceClient struct {
	register *connect.Client[v1.RegisterRequest, v1.RegisterResponse]
	get      *connect.Client[v1.GetRequest, v1.GetResponse]
	list     *connect.Client[v1.ListRequest, v1.ListResponse]
	revoke   *connect.Client[v1.RevokeRequest, v1.RevokeResponse]
	fetch    *connect.Client[v1.FetchRequest, v1.FetchResponse]
}

// Register calls tars.aikeys.v1.AiKeysService.Register.
func (c *aiKeysServiceClient) Register(ctx context.Context, req *connect.Request[v1.RegisterRequest]) (*connect.Response[v1.RegisterResponse], error) {
	return c.register.CallUnary(ctx, req)
}

// Get calls tars.aikeys.v1.AiKeysService.Get.
func (c *aiKeysServiceClient) Get(ctx context.Context, req *connect.Request[v1.GetRequest]) (*connect.Response[v1.GetResponse], error) {
	return c.get.CallUnary(ctx, req)
}

// List calls tars.aikeys.v1.AiKeysService.List.
func (c *aiKeysServiceClient) List(ctx context.Context, req *connect.Request[v1.ListRequest]) (*connect.Response[v1.ListResponse], error) {
	return c.list.CallUnary(ctx, req)
}

// Revoke calls tars.aikeys.v1.AiKeysService.Revoke.
func (c *aiKeysServiceClient) Revoke(ctx context.Context, req *connect.Request[v1.RevokeRequest]) (*connect.Response[v1.RevokeResponse], error) {
	return c.revoke.CallUnary(ctx, req)
}

// Fetch calls tars.aikeys.v1.AiKeysService.Fetch.
func (c *aiKeysServiceClient) Fetch(ctx context.Context, req *connect.Request[v1.FetchRequest]) (*connect.Response[v1.FetchResponse], error) {
	return c.fetch.CallUnary(ctx, req)
}

// AiKeysServiceHandler is an implementation of the tars.aikeys.v1.AiKeysService service.
type AiKeysServiceHandler interface {
	// Register encrypts and stores a provider API key under a project.
	// After this call, inference requests routed to the matching provider
	// for this project will use this key.
	//
	// Scope: account-tier so any project member can register their OWN
	// user-scoped key (user_scope=true). Registering a PROJECT-level key
	// (user_scope=false) additionally requires the caller to be the
	// project's owner -- enforced in-handler against project_members.
	Register(context.Context, *connect.Request[v1.RegisterRequest]) (*connect.Response[v1.RegisterResponse], error)
	// Get returns the metadata record for a single BYOK key. Never returns
	// the plaintext.
	//
	// Scope: account-tier. Any project member may read keys in the project
	// (project-level and the caller's own user-scoped keys); membership is
	// enforced in-handler.
	Get(context.Context, *connect.Request[v1.GetRequest]) (*connect.Response[v1.GetResponse], error)
	// List lists BYOK keys registered under a project. Returns metadata
	// only -- id, provider, name, display_suffix, creation timestamp, and
	// revocation timestamp if revoked. The result includes the project's
	// shared keys plus the caller's own user-scoped keys (other users'
	// user-scoped keys are not returned).
	//
	// Scope: account-tier; membership is enforced in-handler.
	List(context.Context, *connect.Request[v1.ListRequest]) (*connect.Response[v1.ListResponse], error)
	// Revoke marks the key revoked; subsequent Fetches return
	// permission_denied. Inflight cached keys on dataplanes invalidate
	// within sub-second via the revocation channel (milestone C).
	//
	// Scope: account-tier so a member can revoke their OWN user-scoped key.
	// Revoking a PROJECT-level key additionally requires project ownership
	// (enforced in-handler); a member may never revoke another user's
	// user-scoped key.
	Revoke(context.Context, *connect.Request[v1.RevokeRequest]) (*connect.Response[v1.RevokeResponse], error)
	// Fetch is the internal-only RPC the inference handler / dataplane
	// calls on the hot path. Returns the plaintext provider key.
	Fetch(context.Context, *connect.Request[v1.FetchRequest]) (*connect.Response[v1.FetchResponse], error)
}

// NewAiKeysServiceHandler 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 NewAiKeysServiceHandler(svc AiKeysServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
	aiKeysServiceMethods := v1.File_tars_aikeys_v1_aikeys_proto.Services().ByName("AiKeysService").Methods()
	aiKeysServiceRegisterHandler := connect.NewUnaryHandler(
		AiKeysServiceRegisterProcedure,
		svc.Register,
		connect.WithSchema(aiKeysServiceMethods.ByName("Register")),
		connect.WithHandlerOptions(opts...),
	)
	aiKeysServiceGetHandler := connect.NewUnaryHandler(
		AiKeysServiceGetProcedure,
		svc.Get,
		connect.WithSchema(aiKeysServiceMethods.ByName("Get")),
		connect.WithIdempotency(connect.IdempotencyNoSideEffects),
		connect.WithHandlerOptions(opts...),
	)
	aiKeysServiceListHandler := connect.NewUnaryHandler(
		AiKeysServiceListProcedure,
		svc.List,
		connect.WithSchema(aiKeysServiceMethods.ByName("List")),
		connect.WithIdempotency(connect.IdempotencyNoSideEffects),
		connect.WithHandlerOptions(opts...),
	)
	aiKeysServiceRevokeHandler := connect.NewUnaryHandler(
		AiKeysServiceRevokeProcedure,
		svc.Revoke,
		connect.WithSchema(aiKeysServiceMethods.ByName("Revoke")),
		connect.WithHandlerOptions(opts...),
	)
	aiKeysServiceFetchHandler := connect.NewUnaryHandler(
		AiKeysServiceFetchProcedure,
		svc.Fetch,
		connect.WithSchema(aiKeysServiceMethods.ByName("Fetch")),
		connect.WithIdempotency(connect.IdempotencyNoSideEffects),
		connect.WithHandlerOptions(opts...),
	)
	return "/tars.aikeys.v1.AiKeysService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.URL.Path {
		case AiKeysServiceRegisterProcedure:
			aiKeysServiceRegisterHandler.ServeHTTP(w, r)
		case AiKeysServiceGetProcedure:
			aiKeysServiceGetHandler.ServeHTTP(w, r)
		case AiKeysServiceListProcedure:
			aiKeysServiceListHandler.ServeHTTP(w, r)
		case AiKeysServiceRevokeProcedure:
			aiKeysServiceRevokeHandler.ServeHTTP(w, r)
		case AiKeysServiceFetchProcedure:
			aiKeysServiceFetchHandler.ServeHTTP(w, r)
		default:
			http.NotFound(w, r)
		}
	})
}

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

func (UnimplementedAiKeysServiceHandler) Register(context.Context, *connect.Request[v1.RegisterRequest]) (*connect.Response[v1.RegisterResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.aikeys.v1.AiKeysService.Register is not implemented"))
}

func (UnimplementedAiKeysServiceHandler) Get(context.Context, *connect.Request[v1.GetRequest]) (*connect.Response[v1.GetResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.aikeys.v1.AiKeysService.Get is not implemented"))
}

func (UnimplementedAiKeysServiceHandler) List(context.Context, *connect.Request[v1.ListRequest]) (*connect.Response[v1.ListResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.aikeys.v1.AiKeysService.List is not implemented"))
}

func (UnimplementedAiKeysServiceHandler) Revoke(context.Context, *connect.Request[v1.RevokeRequest]) (*connect.Response[v1.RevokeResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.aikeys.v1.AiKeysService.Revoke is not implemented"))
}

func (UnimplementedAiKeysServiceHandler) Fetch(context.Context, *connect.Request[v1.FetchRequest]) (*connect.Response[v1.FetchResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.aikeys.v1.AiKeysService.Fetch is not implemented"))
}
