package autometrics // import "github.com/autometrics-dev/autometrics-go/pkg/autometrics"

import (
	"time"
)

// Those are variables because we cannot have const of this type.
// These variables are not meant to be modified.
var (
	DefBuckets    = []float64{.005, .0075, .01, .025, .05, .075, .1, .25, .5, .75, 1, 2.5, 5, 7.5, 10}
	DefObjectives = []float64{90, 95, 99, 99.9}
)

const (
	AllowCustomLatenciesFlag = "-custom-latency"
)

// Implementation is an enumeration type for the
// possible implementations of metrics to use.
type Implementation int

const (
	PROMETHEUS Implementation = iota
	OTEL
)

const (
	// MiddlewareSpanIDKey is the key to use to index context in middlewares that do not use context.Context.
	MiddlewareSpanIDKey = "autometricsSpanID"
	// MiddlewareTraceIDKey is the key to use to index context in middlewares that do not use context.Context.
	MiddlewareTraceIDKey = "autometricsTraceID"
)

// FunctionID is a unique identifier for a function (on a per-codebase basis)
type FunctionID struct {
	// Function is the name of the function being tracked
	Function string
	// Module is the name of the module containing the function being tracked, up to (and including) the class name
	Module string
}

// CallInfo holds the information about the current function call and its parent names.
type CallInfo struct {
	// Current is the identifier of the function being tracked
	Current FunctionID
	// Parent is the identifirs of the caller of the function being tracked.
	//
	// The parent information is only included for autometricized functions. This
	// means:
	// - if A calls B calls C,
	// - only A and C have autometrics annotations,
	// then the Caller information when working with C is going to be A, _not_ B
	Parent FunctionID
}

// BuildInfo holds the information about the current build of the instrumented code.
type BuildInfo struct {
	// Commit is the commit of the code.
	Commit string
	// Version is the version of the code.
	Version string
	// Branch is the branch of the build of the codebase.
	Branch string
	// Service is the name of the service
	Service string
	// RepositoryURL is the URL of the repository containing the code
	RepositoryURL string
	// RepositoryProvider is the service provider for the repository containing the code
	RepositoryProvider string
}

// AlertConfiguration is the configuration for autometric alerting.
type AlertConfiguration struct {
	// ServiceName is the name of the Service that will appear in the alerts.
	ServiceName string
	// Latency is an optional latency target for the function
	Latency *LatencySlo
	// Success is an optional success rate target for the function
	Success *SuccessSlo
}

// LatencySlo is an objective for latency
type LatencySlo struct {
	// Target is the maximum allowed latency for the endpoint.
	Target time.Duration
	// Objective is the success rate allowed for the given latency, from 0 to 1.
	Objective float64
}

// SuccessSlo is an objective for the success rate of the function
type SuccessSlo struct {
	// Objective is the success rate allowed for the given function, from 0 to 1.
	Objective float64
}
