// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.6.1
//   protoc               unknown
// source: events_mono/growthbook/v1/growthbook_experiment_event.proto

/* eslint-disable */
import { Timestamp } from '../../../google/protobuf/timestamp.js'
import { PublicApiAuth } from '../../common/v1/auth.js'

/**
 * GrowthBook experiment assignment event
 * This event tracks when a user is exposed to an experiment variant
 * See: https://docs.growthbook.io/guide/bigquery
 */
export interface GrowthbookExperimentEvent {
  /** Unique event identifier (for deduplication) */
  event_id?: string | undefined
  /** When user was exposed to experiment (maps to GrowthBook's timestamp column) */
  timestamp?: Date | undefined
  /** Experiment tracking key (maps to GrowthBook's experiment_id column) */
  experiment_id?: string | undefined
  /** Variation index: 0=control, 1+=variants (maps to GrowthBook's variation_id column) */
  variation_id?: number | undefined
  /** Environment where assignment occurred */
  environment?: string | undefined
  /** User attributes at time of assignment */
  user_attributes?: string | undefined
  /** Experiment metadata */
  experiment_metadata?: string | undefined
  /** Device identifier for the client */
  device_id?: string | undefined
  /** Authentication context automatically injected by the API */
  auth?: PublicApiAuth | undefined
  /** Session identifier for tracking user sessions */
  session_id?: string | undefined
  /** Anonymous identifier for unauthenticated users */
  anonymous_id?: string | undefined
  /** Event metadata variables (automatically populated by internal-tools-common event_logging library) */
  event_metadata_vars?: string | undefined
}

function createBaseGrowthbookExperimentEvent(): GrowthbookExperimentEvent {
  return {
    event_id: '',
    timestamp: undefined,
    experiment_id: '',
    variation_id: 0,
    environment: '',
    user_attributes: '',
    experiment_metadata: '',
    device_id: '',
    auth: undefined,
    session_id: '',
    anonymous_id: '',
    event_metadata_vars: '',
  }
}

export const GrowthbookExperimentEvent: MessageFns<GrowthbookExperimentEvent> =
  {
    fromJSON(object: any): GrowthbookExperimentEvent {
      return {
        event_id: isSet(object.event_id)
          ? globalThis.String(object.event_id)
          : '',
        timestamp: isSet(object.timestamp)
          ? fromJsonTimestamp(object.timestamp)
          : undefined,
        experiment_id: isSet(object.experiment_id)
          ? globalThis.String(object.experiment_id)
          : '',
        variation_id: isSet(object.variation_id)
          ? globalThis.Number(object.variation_id)
          : 0,
        environment: isSet(object.environment)
          ? globalThis.String(object.environment)
          : '',
        user_attributes: isSet(object.user_attributes)
          ? globalThis.String(object.user_attributes)
          : '',
        experiment_metadata: isSet(object.experiment_metadata)
          ? globalThis.String(object.experiment_metadata)
          : '',
        device_id: isSet(object.device_id)
          ? globalThis.String(object.device_id)
          : '',
        auth: isSet(object.auth)
          ? PublicApiAuth.fromJSON(object.auth)
          : undefined,
        session_id: isSet(object.session_id)
          ? globalThis.String(object.session_id)
          : '',
        anonymous_id: isSet(object.anonymous_id)
          ? globalThis.String(object.anonymous_id)
          : '',
        event_metadata_vars: isSet(object.event_metadata_vars)
          ? globalThis.String(object.event_metadata_vars)
          : '',
      }
    },

    toJSON(message: GrowthbookExperimentEvent): unknown {
      const obj: any = {}
      if (message.event_id !== undefined) {
        obj.event_id = message.event_id
      }
      if (message.timestamp !== undefined) {
        obj.timestamp = message.timestamp.toISOString()
      }
      if (message.experiment_id !== undefined) {
        obj.experiment_id = message.experiment_id
      }
      if (message.variation_id !== undefined) {
        obj.variation_id = Math.round(message.variation_id)
      }
      if (message.environment !== undefined) {
        obj.environment = message.environment
      }
      if (message.user_attributes !== undefined) {
        obj.user_attributes = message.user_attributes
      }
      if (message.experiment_metadata !== undefined) {
        obj.experiment_metadata = message.experiment_metadata
      }
      if (message.device_id !== undefined) {
        obj.device_id = message.device_id
      }
      if (message.auth !== undefined) {
        obj.auth = PublicApiAuth.toJSON(message.auth)
      }
      if (message.session_id !== undefined) {
        obj.session_id = message.session_id
      }
      if (message.anonymous_id !== undefined) {
        obj.anonymous_id = message.anonymous_id
      }
      if (message.event_metadata_vars !== undefined) {
        obj.event_metadata_vars = message.event_metadata_vars
      }
      return obj
    },

    create<I extends Exact<DeepPartial<GrowthbookExperimentEvent>, I>>(
      base?: I,
    ): GrowthbookExperimentEvent {
      return GrowthbookExperimentEvent.fromPartial(base ?? ({} as any))
    },
    fromPartial<I extends Exact<DeepPartial<GrowthbookExperimentEvent>, I>>(
      object: I,
    ): GrowthbookExperimentEvent {
      const message = createBaseGrowthbookExperimentEvent()
      message.event_id = object.event_id ?? ''
      message.timestamp = object.timestamp ?? undefined
      message.experiment_id = object.experiment_id ?? ''
      message.variation_id = object.variation_id ?? 0
      message.environment = object.environment ?? ''
      message.user_attributes = object.user_attributes ?? ''
      message.experiment_metadata = object.experiment_metadata ?? ''
      message.device_id = object.device_id ?? ''
      message.auth =
        object.auth !== undefined && object.auth !== null
          ? PublicApiAuth.fromPartial(object.auth)
          : undefined
      message.session_id = object.session_id ?? ''
      message.anonymous_id = object.anonymous_id ?? ''
      message.event_metadata_vars = object.event_metadata_vars ?? ''
      return message
    },
  }

type Builtin =
  | Date
  | Function
  | Uint8Array
  | string
  | number
  | boolean
  | undefined

type DeepPartial<T> = T extends Builtin
  ? T
  : T extends globalThis.Array<infer U>
    ? globalThis.Array<DeepPartial<U>>
    : T extends ReadonlyArray<infer U>
      ? ReadonlyArray<DeepPartial<U>>
      : T extends {}
        ? { [K in keyof T]?: DeepPartial<T[K]> }
        : Partial<T>

type KeysOfUnion<T> = T extends T ? keyof T : never
type Exact<P, I extends P> = P extends Builtin
  ? P
  : P & { [K in keyof P]: Exact<P[K], I[K]> } & {
      [K in Exclude<keyof I, KeysOfUnion<P>>]: never
    }

function fromTimestamp(t: Timestamp): Date {
  let millis = (t.seconds || 0) * 1_000
  millis += (t.nanos || 0) / 1_000_000
  return new globalThis.Date(millis)
}

function fromJsonTimestamp(o: any): Date {
  if (o instanceof globalThis.Date) {
    return o
  } else if (typeof o === 'string') {
    return new globalThis.Date(o)
  } else {
    return fromTimestamp(Timestamp.fromJSON(o))
  }
}

function isSet(value: any): boolean {
  return value !== null && value !== undefined
}

interface MessageFns<T> {
  fromJSON(object: any): T
  toJSON(message: T): unknown
  create<I extends Exact<DeepPartial<T>, I>>(base?: I): T
  fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T
}

