// TelemetryService -- public CRUD surface for per-user OTel export
// configurations (sink URL + protocol + auth) the management plane
// forwards traces/metrics/logs to.
//
// Underlying storage is the existing `telemetry_configs` table the
// admin.v1 AdminService already manages. This file promotes those RPCs
// onto the proto-driven IA surface; the handler in
// `svc/internal/telemetrysvc/` is a thin shim that delegates to the
// same TelemetryConfigRepository -- no parallel SQL.
//
// Scoping model: telemetry config now has two scopes that share the same
// (customer, project) address:
//   - PER-USER config (Create/List/Get/Update/Delete) is account-tier:
//     every member manages their OWN config, keyed by the authenticated
//     caller's user_id.
//   - PROJECT-level config (SetProjectTelemetryConfig /
//     GetProjectTelemetryConfig) is project_owner-tier: the project owner
//     sets a shared default for the project.
// At telemetry-emit time the resolver PREFERS the user's own config and
// falls back to the project-level config (see telemetrysvc.ResolveEffective
// and the consumer wiring note there).
//
// Storage note: the underlying `telemetry_configs` table is user-keyed
// (one row per (user_id, telemetry_type)). Project-level rows reuse that
// table under a deterministic synthetic owner key
// ("proj::<customer>::<project>") so no schema migration to the admin
// telemetry table is required; the public surface and the override
// resolution live in the telemetrysvc shim.

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

package telemetryv1connect

import (
	connect "connectrpc.com/connect"
	context "context"
	errors "errors"
	v1 "github.com/tetrateio/agentrouter-go/genapi/api/tars/telemetry/v1"
	emptypb "google.golang.org/protobuf/types/known/emptypb"
	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 (
	// TelemetryServiceName is the fully-qualified name of the TelemetryService service.
	TelemetryServiceName = "tars.telemetry.v1.TelemetryService"
)

// 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 (
	// TelemetryServiceCreateTelemetryConfigProcedure is the fully-qualified name of the
	// TelemetryService's CreateTelemetryConfig RPC.
	TelemetryServiceCreateTelemetryConfigProcedure = "/tars.telemetry.v1.TelemetryService/CreateTelemetryConfig"
	// TelemetryServiceListTelemetryConfigsProcedure is the fully-qualified name of the
	// TelemetryService's ListTelemetryConfigs RPC.
	TelemetryServiceListTelemetryConfigsProcedure = "/tars.telemetry.v1.TelemetryService/ListTelemetryConfigs"
	// TelemetryServiceGetTelemetryConfigProcedure is the fully-qualified name of the TelemetryService's
	// GetTelemetryConfig RPC.
	TelemetryServiceGetTelemetryConfigProcedure = "/tars.telemetry.v1.TelemetryService/GetTelemetryConfig"
	// TelemetryServiceUpdateTelemetryConfigProcedure is the fully-qualified name of the
	// TelemetryService's UpdateTelemetryConfig RPC.
	TelemetryServiceUpdateTelemetryConfigProcedure = "/tars.telemetry.v1.TelemetryService/UpdateTelemetryConfig"
	// TelemetryServiceDeleteTelemetryConfigProcedure is the fully-qualified name of the
	// TelemetryService's DeleteTelemetryConfig RPC.
	TelemetryServiceDeleteTelemetryConfigProcedure = "/tars.telemetry.v1.TelemetryService/DeleteTelemetryConfig"
	// TelemetryServiceSetProjectTelemetryConfigProcedure is the fully-qualified name of the
	// TelemetryService's SetProjectTelemetryConfig RPC.
	TelemetryServiceSetProjectTelemetryConfigProcedure = "/tars.telemetry.v1.TelemetryService/SetProjectTelemetryConfig"
	// TelemetryServiceGetProjectTelemetryConfigProcedure is the fully-qualified name of the
	// TelemetryService's GetProjectTelemetryConfig RPC.
	TelemetryServiceGetProjectTelemetryConfigProcedure = "/tars.telemetry.v1.TelemetryService/GetProjectTelemetryConfig"
)

// TelemetryServiceClient is a client for the tars.telemetry.v1.TelemetryService service.
type TelemetryServiceClient interface {
	// CreateTelemetryConfig creates a new OTel export configuration.
	CreateTelemetryConfig(context.Context, *connect.Request[v1.CreateTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error)
	// ListTelemetryConfigs lists every configuration owned by the caller
	// within the (customer, project) scope.
	ListTelemetryConfigs(context.Context, *connect.Request[v1.ListTelemetryConfigsRequest]) (*connect.Response[v1.ListTelemetryConfigsResponse], error)
	// GetTelemetryConfig returns a single configuration by id.
	GetTelemetryConfig(context.Context, *connect.Request[v1.GetTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error)
	// UpdateTelemetryConfig updates a configuration's mutable fields.
	UpdateTelemetryConfig(context.Context, *connect.Request[v1.UpdateTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error)
	// DeleteTelemetryConfig removes a configuration.
	DeleteTelemetryConfig(context.Context, *connect.Request[v1.DeleteTelemetryConfigRequest]) (*connect.Response[emptypb.Empty], error)
	// SetProjectTelemetryConfig upserts the PROJECT-level telemetry export
	// config (the shared default applied to project members who have no
	// config of their own). Project-owner-tier: only the project's owner may
	// set it. A user's own per-user config OVERRIDES this at emit time.
	SetProjectTelemetryConfig(context.Context, *connect.Request[v1.SetProjectTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error)
	// GetProjectTelemetryConfig returns the PROJECT-level telemetry config.
	// Project-owner-tier (the shared project default is managed by owners).
	GetProjectTelemetryConfig(context.Context, *connect.Request[v1.GetProjectTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error)
}

// NewTelemetryServiceClient constructs a client for the tars.telemetry.v1.TelemetryService 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 NewTelemetryServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) TelemetryServiceClient {
	baseURL = strings.TrimRight(baseURL, "/")
	telemetryServiceMethods := v1.File_tars_telemetry_v1_telemetry_proto.Services().ByName("TelemetryService").Methods()
	return &telemetryServiceClient{
		createTelemetryConfig: connect.NewClient[v1.CreateTelemetryConfigRequest, v1.TelemetryConfig](
			httpClient,
			baseURL+TelemetryServiceCreateTelemetryConfigProcedure,
			connect.WithSchema(telemetryServiceMethods.ByName("CreateTelemetryConfig")),
			connect.WithClientOptions(opts...),
		),
		listTelemetryConfigs: connect.NewClient[v1.ListTelemetryConfigsRequest, v1.ListTelemetryConfigsResponse](
			httpClient,
			baseURL+TelemetryServiceListTelemetryConfigsProcedure,
			connect.WithSchema(telemetryServiceMethods.ByName("ListTelemetryConfigs")),
			connect.WithIdempotency(connect.IdempotencyNoSideEffects),
			connect.WithClientOptions(opts...),
		),
		getTelemetryConfig: connect.NewClient[v1.GetTelemetryConfigRequest, v1.TelemetryConfig](
			httpClient,
			baseURL+TelemetryServiceGetTelemetryConfigProcedure,
			connect.WithSchema(telemetryServiceMethods.ByName("GetTelemetryConfig")),
			connect.WithIdempotency(connect.IdempotencyNoSideEffects),
			connect.WithClientOptions(opts...),
		),
		updateTelemetryConfig: connect.NewClient[v1.UpdateTelemetryConfigRequest, v1.TelemetryConfig](
			httpClient,
			baseURL+TelemetryServiceUpdateTelemetryConfigProcedure,
			connect.WithSchema(telemetryServiceMethods.ByName("UpdateTelemetryConfig")),
			connect.WithClientOptions(opts...),
		),
		deleteTelemetryConfig: connect.NewClient[v1.DeleteTelemetryConfigRequest, emptypb.Empty](
			httpClient,
			baseURL+TelemetryServiceDeleteTelemetryConfigProcedure,
			connect.WithSchema(telemetryServiceMethods.ByName("DeleteTelemetryConfig")),
			connect.WithClientOptions(opts...),
		),
		setProjectTelemetryConfig: connect.NewClient[v1.SetProjectTelemetryConfigRequest, v1.TelemetryConfig](
			httpClient,
			baseURL+TelemetryServiceSetProjectTelemetryConfigProcedure,
			connect.WithSchema(telemetryServiceMethods.ByName("SetProjectTelemetryConfig")),
			connect.WithClientOptions(opts...),
		),
		getProjectTelemetryConfig: connect.NewClient[v1.GetProjectTelemetryConfigRequest, v1.TelemetryConfig](
			httpClient,
			baseURL+TelemetryServiceGetProjectTelemetryConfigProcedure,
			connect.WithSchema(telemetryServiceMethods.ByName("GetProjectTelemetryConfig")),
			connect.WithIdempotency(connect.IdempotencyNoSideEffects),
			connect.WithClientOptions(opts...),
		),
	}
}

// telemetryServiceClient implements TelemetryServiceClient.
type telemetryServiceClient struct {
	createTelemetryConfig     *connect.Client[v1.CreateTelemetryConfigRequest, v1.TelemetryConfig]
	listTelemetryConfigs      *connect.Client[v1.ListTelemetryConfigsRequest, v1.ListTelemetryConfigsResponse]
	getTelemetryConfig        *connect.Client[v1.GetTelemetryConfigRequest, v1.TelemetryConfig]
	updateTelemetryConfig     *connect.Client[v1.UpdateTelemetryConfigRequest, v1.TelemetryConfig]
	deleteTelemetryConfig     *connect.Client[v1.DeleteTelemetryConfigRequest, emptypb.Empty]
	setProjectTelemetryConfig *connect.Client[v1.SetProjectTelemetryConfigRequest, v1.TelemetryConfig]
	getProjectTelemetryConfig *connect.Client[v1.GetProjectTelemetryConfigRequest, v1.TelemetryConfig]
}

// CreateTelemetryConfig calls tars.telemetry.v1.TelemetryService.CreateTelemetryConfig.
func (c *telemetryServiceClient) CreateTelemetryConfig(ctx context.Context, req *connect.Request[v1.CreateTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error) {
	return c.createTelemetryConfig.CallUnary(ctx, req)
}

// ListTelemetryConfigs calls tars.telemetry.v1.TelemetryService.ListTelemetryConfigs.
func (c *telemetryServiceClient) ListTelemetryConfigs(ctx context.Context, req *connect.Request[v1.ListTelemetryConfigsRequest]) (*connect.Response[v1.ListTelemetryConfigsResponse], error) {
	return c.listTelemetryConfigs.CallUnary(ctx, req)
}

// GetTelemetryConfig calls tars.telemetry.v1.TelemetryService.GetTelemetryConfig.
func (c *telemetryServiceClient) GetTelemetryConfig(ctx context.Context, req *connect.Request[v1.GetTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error) {
	return c.getTelemetryConfig.CallUnary(ctx, req)
}

// UpdateTelemetryConfig calls tars.telemetry.v1.TelemetryService.UpdateTelemetryConfig.
func (c *telemetryServiceClient) UpdateTelemetryConfig(ctx context.Context, req *connect.Request[v1.UpdateTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error) {
	return c.updateTelemetryConfig.CallUnary(ctx, req)
}

// DeleteTelemetryConfig calls tars.telemetry.v1.TelemetryService.DeleteTelemetryConfig.
func (c *telemetryServiceClient) DeleteTelemetryConfig(ctx context.Context, req *connect.Request[v1.DeleteTelemetryConfigRequest]) (*connect.Response[emptypb.Empty], error) {
	return c.deleteTelemetryConfig.CallUnary(ctx, req)
}

// SetProjectTelemetryConfig calls tars.telemetry.v1.TelemetryService.SetProjectTelemetryConfig.
func (c *telemetryServiceClient) SetProjectTelemetryConfig(ctx context.Context, req *connect.Request[v1.SetProjectTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error) {
	return c.setProjectTelemetryConfig.CallUnary(ctx, req)
}

// GetProjectTelemetryConfig calls tars.telemetry.v1.TelemetryService.GetProjectTelemetryConfig.
func (c *telemetryServiceClient) GetProjectTelemetryConfig(ctx context.Context, req *connect.Request[v1.GetProjectTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error) {
	return c.getProjectTelemetryConfig.CallUnary(ctx, req)
}

// TelemetryServiceHandler is an implementation of the tars.telemetry.v1.TelemetryService service.
type TelemetryServiceHandler interface {
	// CreateTelemetryConfig creates a new OTel export configuration.
	CreateTelemetryConfig(context.Context, *connect.Request[v1.CreateTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error)
	// ListTelemetryConfigs lists every configuration owned by the caller
	// within the (customer, project) scope.
	ListTelemetryConfigs(context.Context, *connect.Request[v1.ListTelemetryConfigsRequest]) (*connect.Response[v1.ListTelemetryConfigsResponse], error)
	// GetTelemetryConfig returns a single configuration by id.
	GetTelemetryConfig(context.Context, *connect.Request[v1.GetTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error)
	// UpdateTelemetryConfig updates a configuration's mutable fields.
	UpdateTelemetryConfig(context.Context, *connect.Request[v1.UpdateTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error)
	// DeleteTelemetryConfig removes a configuration.
	DeleteTelemetryConfig(context.Context, *connect.Request[v1.DeleteTelemetryConfigRequest]) (*connect.Response[emptypb.Empty], error)
	// SetProjectTelemetryConfig upserts the PROJECT-level telemetry export
	// config (the shared default applied to project members who have no
	// config of their own). Project-owner-tier: only the project's owner may
	// set it. A user's own per-user config OVERRIDES this at emit time.
	SetProjectTelemetryConfig(context.Context, *connect.Request[v1.SetProjectTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error)
	// GetProjectTelemetryConfig returns the PROJECT-level telemetry config.
	// Project-owner-tier (the shared project default is managed by owners).
	GetProjectTelemetryConfig(context.Context, *connect.Request[v1.GetProjectTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error)
}

// NewTelemetryServiceHandler 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 NewTelemetryServiceHandler(svc TelemetryServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
	telemetryServiceMethods := v1.File_tars_telemetry_v1_telemetry_proto.Services().ByName("TelemetryService").Methods()
	telemetryServiceCreateTelemetryConfigHandler := connect.NewUnaryHandler(
		TelemetryServiceCreateTelemetryConfigProcedure,
		svc.CreateTelemetryConfig,
		connect.WithSchema(telemetryServiceMethods.ByName("CreateTelemetryConfig")),
		connect.WithHandlerOptions(opts...),
	)
	telemetryServiceListTelemetryConfigsHandler := connect.NewUnaryHandler(
		TelemetryServiceListTelemetryConfigsProcedure,
		svc.ListTelemetryConfigs,
		connect.WithSchema(telemetryServiceMethods.ByName("ListTelemetryConfigs")),
		connect.WithIdempotency(connect.IdempotencyNoSideEffects),
		connect.WithHandlerOptions(opts...),
	)
	telemetryServiceGetTelemetryConfigHandler := connect.NewUnaryHandler(
		TelemetryServiceGetTelemetryConfigProcedure,
		svc.GetTelemetryConfig,
		connect.WithSchema(telemetryServiceMethods.ByName("GetTelemetryConfig")),
		connect.WithIdempotency(connect.IdempotencyNoSideEffects),
		connect.WithHandlerOptions(opts...),
	)
	telemetryServiceUpdateTelemetryConfigHandler := connect.NewUnaryHandler(
		TelemetryServiceUpdateTelemetryConfigProcedure,
		svc.UpdateTelemetryConfig,
		connect.WithSchema(telemetryServiceMethods.ByName("UpdateTelemetryConfig")),
		connect.WithHandlerOptions(opts...),
	)
	telemetryServiceDeleteTelemetryConfigHandler := connect.NewUnaryHandler(
		TelemetryServiceDeleteTelemetryConfigProcedure,
		svc.DeleteTelemetryConfig,
		connect.WithSchema(telemetryServiceMethods.ByName("DeleteTelemetryConfig")),
		connect.WithHandlerOptions(opts...),
	)
	telemetryServiceSetProjectTelemetryConfigHandler := connect.NewUnaryHandler(
		TelemetryServiceSetProjectTelemetryConfigProcedure,
		svc.SetProjectTelemetryConfig,
		connect.WithSchema(telemetryServiceMethods.ByName("SetProjectTelemetryConfig")),
		connect.WithHandlerOptions(opts...),
	)
	telemetryServiceGetProjectTelemetryConfigHandler := connect.NewUnaryHandler(
		TelemetryServiceGetProjectTelemetryConfigProcedure,
		svc.GetProjectTelemetryConfig,
		connect.WithSchema(telemetryServiceMethods.ByName("GetProjectTelemetryConfig")),
		connect.WithIdempotency(connect.IdempotencyNoSideEffects),
		connect.WithHandlerOptions(opts...),
	)
	return "/tars.telemetry.v1.TelemetryService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.URL.Path {
		case TelemetryServiceCreateTelemetryConfigProcedure:
			telemetryServiceCreateTelemetryConfigHandler.ServeHTTP(w, r)
		case TelemetryServiceListTelemetryConfigsProcedure:
			telemetryServiceListTelemetryConfigsHandler.ServeHTTP(w, r)
		case TelemetryServiceGetTelemetryConfigProcedure:
			telemetryServiceGetTelemetryConfigHandler.ServeHTTP(w, r)
		case TelemetryServiceUpdateTelemetryConfigProcedure:
			telemetryServiceUpdateTelemetryConfigHandler.ServeHTTP(w, r)
		case TelemetryServiceDeleteTelemetryConfigProcedure:
			telemetryServiceDeleteTelemetryConfigHandler.ServeHTTP(w, r)
		case TelemetryServiceSetProjectTelemetryConfigProcedure:
			telemetryServiceSetProjectTelemetryConfigHandler.ServeHTTP(w, r)
		case TelemetryServiceGetProjectTelemetryConfigProcedure:
			telemetryServiceGetProjectTelemetryConfigHandler.ServeHTTP(w, r)
		default:
			http.NotFound(w, r)
		}
	})
}

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

func (UnimplementedTelemetryServiceHandler) CreateTelemetryConfig(context.Context, *connect.Request[v1.CreateTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.telemetry.v1.TelemetryService.CreateTelemetryConfig is not implemented"))
}

func (UnimplementedTelemetryServiceHandler) ListTelemetryConfigs(context.Context, *connect.Request[v1.ListTelemetryConfigsRequest]) (*connect.Response[v1.ListTelemetryConfigsResponse], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.telemetry.v1.TelemetryService.ListTelemetryConfigs is not implemented"))
}

func (UnimplementedTelemetryServiceHandler) GetTelemetryConfig(context.Context, *connect.Request[v1.GetTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.telemetry.v1.TelemetryService.GetTelemetryConfig is not implemented"))
}

func (UnimplementedTelemetryServiceHandler) UpdateTelemetryConfig(context.Context, *connect.Request[v1.UpdateTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.telemetry.v1.TelemetryService.UpdateTelemetryConfig is not implemented"))
}

func (UnimplementedTelemetryServiceHandler) DeleteTelemetryConfig(context.Context, *connect.Request[v1.DeleteTelemetryConfigRequest]) (*connect.Response[emptypb.Empty], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.telemetry.v1.TelemetryService.DeleteTelemetryConfig is not implemented"))
}

func (UnimplementedTelemetryServiceHandler) SetProjectTelemetryConfig(context.Context, *connect.Request[v1.SetProjectTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.telemetry.v1.TelemetryService.SetProjectTelemetryConfig is not implemented"))
}

func (UnimplementedTelemetryServiceHandler) GetProjectTelemetryConfig(context.Context, *connect.Request[v1.GetProjectTelemetryConfigRequest]) (*connect.Response[v1.TelemetryConfig], error) {
	return nil, connect.NewError(connect.CodeUnimplemented, errors.New("tars.telemetry.v1.TelemetryService.GetProjectTelemetryConfig is not implemented"))
}
