// Code generated by Fern. DO NOT EDIT.

package api

import (
	json "encoding/json"
	fmt "fmt"
	big "math/big"
	internal "pentagi/pkg/observability/langfuse/api/internal"
	time "time"
)

var (
	observationsV2GetManyRequestFieldFields              = big.NewInt(1 << 0)
	observationsV2GetManyRequestFieldExpandMetadata      = big.NewInt(1 << 1)
	observationsV2GetManyRequestFieldLimit               = big.NewInt(1 << 2)
	observationsV2GetManyRequestFieldCursor              = big.NewInt(1 << 3)
	observationsV2GetManyRequestFieldParseIoAsJSON       = big.NewInt(1 << 4)
	observationsV2GetManyRequestFieldName                = big.NewInt(1 << 5)
	observationsV2GetManyRequestFieldUserID              = big.NewInt(1 << 6)
	observationsV2GetManyRequestFieldType                = big.NewInt(1 << 7)
	observationsV2GetManyRequestFieldTraceID             = big.NewInt(1 << 8)
	observationsV2GetManyRequestFieldLevel               = big.NewInt(1 << 9)
	observationsV2GetManyRequestFieldParentObservationID = big.NewInt(1 << 10)
	observationsV2GetManyRequestFieldEnvironment         = big.NewInt(1 << 11)
	observationsV2GetManyRequestFieldFromStartTime       = big.NewInt(1 << 12)
	observationsV2GetManyRequestFieldToStartTime         = big.NewInt(1 << 13)
	observationsV2GetManyRequestFieldVersion             = big.NewInt(1 << 14)
	observationsV2GetManyRequestFieldFilter              = big.NewInt(1 << 15)
)

type ObservationsV2GetManyRequest struct {
	// Comma-separated list of field groups to include in the response.
	// Available groups: core, basic, time, io, metadata, model, usage, prompt, metrics.
	// If not specified, `core` and `basic` field groups are returned.
	// Example: "basic,usage,model"
	Fields *string `json:"-" url:"fields,omitempty"`
	// Comma-separated list of metadata keys to return non-truncated.
	// By default, metadata values over 200 characters are truncated.
	// Use this parameter to retrieve full values for specific keys.
	// Example: "key1,key2"
	ExpandMetadata *string `json:"-" url:"expandMetadata,omitempty"`
	// Number of items to return per page. Maximum 1000, default 50.
	Limit *int `json:"-" url:"limit,omitempty"`
	// Base64-encoded cursor for pagination. Use the cursor from the previous response to get the next page.
	Cursor *string `json:"-" url:"cursor,omitempty"`
	// Set to `true` to parse input/output fields as JSON, or `false` to return raw strings.
	// Defaults to `false` if not provided.
	ParseIoAsJSON *bool   `json:"-" url:"parseIoAsJson,omitempty"`
	Name          *string `json:"-" url:"name,omitempty"`
	UserID        *string `json:"-" url:"userId,omitempty"`
	// Filter by observation type (e.g., "GENERATION", "SPAN", "EVENT", "AGENT", "TOOL", "CHAIN", "RETRIEVER", "EVALUATOR", "EMBEDDING", "GUARDRAIL")
	Type    *string `json:"-" url:"type,omitempty"`
	TraceID *string `json:"-" url:"traceId,omitempty"`
	// Optional filter for observations with a specific level (e.g. "DEBUG", "DEFAULT", "WARNING", "ERROR").
	Level               *ObservationLevel `json:"-" url:"level,omitempty"`
	ParentObservationID *string           `json:"-" url:"parentObservationId,omitempty"`
	// Optional filter for observations where the environment is one of the provided values.
	Environment []*string `json:"-" url:"environment,omitempty"`
	// Retrieve only observations with a start_time on or after this datetime (ISO 8601).
	FromStartTime *time.Time `json:"-" url:"fromStartTime,omitempty"`
	// Retrieve only observations with a start_time before this datetime (ISO 8601).
	ToStartTime *time.Time `json:"-" url:"toStartTime,omitempty"`
	// Optional filter to only include observations with a certain version.
	Version *string `json:"-" url:"version,omitempty"`
	// JSON string containing an array of filter conditions. When provided, this takes precedence over query parameter filters (userId, name, type, level, environment, fromStartTime, ...).
	//
	// ## Filter Structure
	// Each filter condition has the following structure:
	// ```json
	// [
	//
	//	{
	//	  "type": string,           // Required. One of: "datetime", "string", "number", "stringOptions", "categoryOptions", "arrayOptions", "stringObject", "numberObject", "boolean", "null"
	//	  "column": string,         // Required. Column to filter on (see available columns below)
	//	  "operator": string,       // Required. Operator based on type:
	//	                            // - datetime: ">", "<", ">=", "<="
	//	                            // - string: "=", "contains", "does not contain", "starts with", "ends with"
	//	                            // - stringOptions: "any of", "none of"
	//	                            // - categoryOptions: "any of", "none of"
	//	                            // - arrayOptions: "any of", "none of", "all of"
	//	                            // - number: "=", ">", "<", ">=", "<="
	//	                            // - stringObject: "=", "contains", "does not contain", "starts with", "ends with"
	//	                            // - numberObject: "=", ">", "<", ">=", "<="
	//	                            // - boolean: "=", "<>"
	//	                            // - null: "is null", "is not null"
	//	  "value": any,             // Required (except for null type). Value to compare against. Type depends on filter type
	//	  "key": string             // Required only for stringObject, numberObject, and categoryOptions types when filtering on nested fields like metadata
	//	}
	//
	// ]
	// ```
	//
	// ## Available Columns
	//
	// ### Core Observation Fields
	// - `id` (string) - Observation ID
	// - `type` (string) - Observation type (SPAN, GENERATION, EVENT)
	// - `name` (string) - Observation name
	// - `traceId` (string) - Associated trace ID
	// - `startTime` (datetime) - Observation start time
	// - `endTime` (datetime) - Observation end time
	// - `environment` (string) - Environment tag
	// - `level` (string) - Log level (DEBUG, DEFAULT, WARNING, ERROR)
	// - `statusMessage` (string) - Status message
	// - `version` (string) - Version tag
	// - `userId` (string) - User ID
	// - `sessionId` (string) - Session ID
	//
	// ### Trace-Related Fields
	// - `traceName` (string) - Name of the parent trace
	// - `traceTags` (arrayOptions) - Tags from the parent trace
	// - `tags` (arrayOptions) - Alias for traceTags
	//
	// ### Performance Metrics
	// - `latency` (number) - Latency in seconds (calculated: end_time - start_time)
	// - `timeToFirstToken` (number) - Time to first token in seconds
	// - `tokensPerSecond` (number) - Output tokens per second
	//
	// ### Token Usage
	// - `inputTokens` (number) - Number of input tokens
	// - `outputTokens` (number) - Number of output tokens
	// - `totalTokens` (number) - Total tokens (alias: `tokens`)
	//
	// ### Cost Metrics
	// - `inputCost` (number) - Input cost in USD
	// - `outputCost` (number) - Output cost in USD
	// - `totalCost` (number) - Total cost in USD
	//
	// ### Model Information
	// - `model` (string) - Provided model name (alias: `providedModelName`)
	// - `promptName` (string) - Associated prompt name
	// - `promptVersion` (number) - Associated prompt version
	//
	// ### Structured Data
	// - `metadata` (stringObject/numberObject/categoryOptions) - Metadata key-value pairs. Use `key` parameter to filter on specific metadata keys.
	//
	// ## Filter Examples
	// ```json
	// [
	//
	//	{
	//	  "type": "string",
	//	  "column": "type",
	//	  "operator": "=",
	//	  "value": "GENERATION"
	//	},
	//	{
	//	  "type": "number",
	//	  "column": "latency",
	//	  "operator": ">=",
	//	  "value": 2.5
	//	},
	//	{
	//	  "type": "stringObject",
	//	  "column": "metadata",
	//	  "key": "environment",
	//	  "operator": "=",
	//	  "value": "production"
	//	}
	//
	// ]
	// ```
	Filter *string `json:"-" url:"filter,omitempty"`

	// Private bitmask of fields set to an explicit value and therefore not to be omitted
	explicitFields *big.Int `json:"-" url:"-"`
}

func (o *ObservationsV2GetManyRequest) require(field *big.Int) {
	if o.explicitFields == nil {
		o.explicitFields = big.NewInt(0)
	}
	o.explicitFields.Or(o.explicitFields, field)
}

// SetFields sets the Fields field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetFields(fields *string) {
	o.Fields = fields
	o.require(observationsV2GetManyRequestFieldFields)
}

// SetExpandMetadata sets the ExpandMetadata field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetExpandMetadata(expandMetadata *string) {
	o.ExpandMetadata = expandMetadata
	o.require(observationsV2GetManyRequestFieldExpandMetadata)
}

// SetLimit sets the Limit field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetLimit(limit *int) {
	o.Limit = limit
	o.require(observationsV2GetManyRequestFieldLimit)
}

// SetCursor sets the Cursor field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetCursor(cursor *string) {
	o.Cursor = cursor
	o.require(observationsV2GetManyRequestFieldCursor)
}

// SetParseIoAsJSON sets the ParseIoAsJSON field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetParseIoAsJSON(parseIoAsJSON *bool) {
	o.ParseIoAsJSON = parseIoAsJSON
	o.require(observationsV2GetManyRequestFieldParseIoAsJSON)
}

// SetName sets the Name field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetName(name *string) {
	o.Name = name
	o.require(observationsV2GetManyRequestFieldName)
}

// SetUserID sets the UserID field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetUserID(userID *string) {
	o.UserID = userID
	o.require(observationsV2GetManyRequestFieldUserID)
}

// SetType sets the Type field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetType(type_ *string) {
	o.Type = type_
	o.require(observationsV2GetManyRequestFieldType)
}

// SetTraceID sets the TraceID field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetTraceID(traceID *string) {
	o.TraceID = traceID
	o.require(observationsV2GetManyRequestFieldTraceID)
}

// SetLevel sets the Level field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetLevel(level *ObservationLevel) {
	o.Level = level
	o.require(observationsV2GetManyRequestFieldLevel)
}

// SetParentObservationID sets the ParentObservationID field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetParentObservationID(parentObservationID *string) {
	o.ParentObservationID = parentObservationID
	o.require(observationsV2GetManyRequestFieldParentObservationID)
}

// SetEnvironment sets the Environment field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetEnvironment(environment []*string) {
	o.Environment = environment
	o.require(observationsV2GetManyRequestFieldEnvironment)
}

// SetFromStartTime sets the FromStartTime field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetFromStartTime(fromStartTime *time.Time) {
	o.FromStartTime = fromStartTime
	o.require(observationsV2GetManyRequestFieldFromStartTime)
}

// SetToStartTime sets the ToStartTime field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetToStartTime(toStartTime *time.Time) {
	o.ToStartTime = toStartTime
	o.require(observationsV2GetManyRequestFieldToStartTime)
}

// SetVersion sets the Version field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetVersion(version *string) {
	o.Version = version
	o.require(observationsV2GetManyRequestFieldVersion)
}

// SetFilter sets the Filter field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2GetManyRequest) SetFilter(filter *string) {
	o.Filter = filter
	o.require(observationsV2GetManyRequestFieldFilter)
}

// Metadata for cursor-based pagination
var (
	observationsV2MetaFieldCursor = big.NewInt(1 << 0)
)

type ObservationsV2Meta struct {
	// Base64-encoded cursor to use for retrieving the next page. If not present, there are no more results.
	Cursor *string `json:"cursor,omitempty" url:"cursor,omitempty"`

	// Private bitmask of fields set to an explicit value and therefore not to be omitted
	explicitFields *big.Int `json:"-" url:"-"`

	extraProperties map[string]interface{}
	rawJSON         json.RawMessage
}

func (o *ObservationsV2Meta) GetCursor() *string {
	if o == nil {
		return nil
	}
	return o.Cursor
}

func (o *ObservationsV2Meta) GetExtraProperties() map[string]interface{} {
	return o.extraProperties
}

func (o *ObservationsV2Meta) require(field *big.Int) {
	if o.explicitFields == nil {
		o.explicitFields = big.NewInt(0)
	}
	o.explicitFields.Or(o.explicitFields, field)
}

// SetCursor sets the Cursor field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2Meta) SetCursor(cursor *string) {
	o.Cursor = cursor
	o.require(observationsV2MetaFieldCursor)
}

func (o *ObservationsV2Meta) UnmarshalJSON(data []byte) error {
	type unmarshaler ObservationsV2Meta
	var value unmarshaler
	if err := json.Unmarshal(data, &value); err != nil {
		return err
	}
	*o = ObservationsV2Meta(value)
	extraProperties, err := internal.ExtractExtraProperties(data, *o)
	if err != nil {
		return err
	}
	o.extraProperties = extraProperties
	o.rawJSON = json.RawMessage(data)
	return nil
}

func (o *ObservationsV2Meta) MarshalJSON() ([]byte, error) {
	type embed ObservationsV2Meta
	var marshaler = struct {
		embed
	}{
		embed: embed(*o),
	}
	explicitMarshaler := internal.HandleExplicitFields(marshaler, o.explicitFields)
	return json.Marshal(explicitMarshaler)
}

func (o *ObservationsV2Meta) String() string {
	if len(o.rawJSON) > 0 {
		if value, err := internal.StringifyJSON(o.rawJSON); err == nil {
			return value
		}
	}
	if value, err := internal.StringifyJSON(o); err == nil {
		return value
	}
	return fmt.Sprintf("%#v", o)
}

// Response containing observations with field-group-based filtering and cursor-based pagination.
//
// The `data` array contains observation objects with only the requested field groups included.
// Use the `cursor` in `meta` to retrieve the next page of results.
var (
	observationsV2ResponseFieldData = big.NewInt(1 << 0)
	observationsV2ResponseFieldMeta = big.NewInt(1 << 1)
)

type ObservationsV2Response struct {
	// Array of observation objects. Fields included depend on the `fields` parameter in the request.
	Data []map[string]interface{} `json:"data" url:"data"`
	Meta *ObservationsV2Meta      `json:"meta" url:"meta"`

	// Private bitmask of fields set to an explicit value and therefore not to be omitted
	explicitFields *big.Int `json:"-" url:"-"`

	extraProperties map[string]interface{}
	rawJSON         json.RawMessage
}

func (o *ObservationsV2Response) GetData() []map[string]interface{} {
	if o == nil {
		return nil
	}
	return o.Data
}

func (o *ObservationsV2Response) GetMeta() *ObservationsV2Meta {
	if o == nil {
		return nil
	}
	return o.Meta
}

func (o *ObservationsV2Response) GetExtraProperties() map[string]interface{} {
	return o.extraProperties
}

func (o *ObservationsV2Response) require(field *big.Int) {
	if o.explicitFields == nil {
		o.explicitFields = big.NewInt(0)
	}
	o.explicitFields.Or(o.explicitFields, field)
}

// SetData sets the Data field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2Response) SetData(data []map[string]interface{}) {
	o.Data = data
	o.require(observationsV2ResponseFieldData)
}

// SetMeta sets the Meta field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (o *ObservationsV2Response) SetMeta(meta *ObservationsV2Meta) {
	o.Meta = meta
	o.require(observationsV2ResponseFieldMeta)
}

func (o *ObservationsV2Response) UnmarshalJSON(data []byte) error {
	type unmarshaler ObservationsV2Response
	var value unmarshaler
	if err := json.Unmarshal(data, &value); err != nil {
		return err
	}
	*o = ObservationsV2Response(value)
	extraProperties, err := internal.ExtractExtraProperties(data, *o)
	if err != nil {
		return err
	}
	o.extraProperties = extraProperties
	o.rawJSON = json.RawMessage(data)
	return nil
}

func (o *ObservationsV2Response) MarshalJSON() ([]byte, error) {
	type embed ObservationsV2Response
	var marshaler = struct {
		embed
	}{
		embed: embed(*o),
	}
	explicitMarshaler := internal.HandleExplicitFields(marshaler, o.explicitFields)
	return json.Marshal(explicitMarshaler)
}

func (o *ObservationsV2Response) String() string {
	if len(o.rawJSON) > 0 {
		if value, err := internal.StringifyJSON(o.rawJSON); err == nil {
			return value
		}
	}
	if value, err := internal.StringifyJSON(o); err == nil {
		return value
	}
	return fmt.Sprintf("%#v", o)
}
