import { UserTraits } from './user'


export type SegmentEventType = 'page' | 'track' | 'identify'

type SegmentEventDefinition<T extends SegmentEventType, EventProperties extends Record<string, unknown>> = {
  type: T
  anonymousId: string
  userId: string
  messageId: string

  // The following can be present or absent, not required for Inspector to work nominally

  integrations?: Record<string, unknown>
  context?: Record<string, unknown>
} & EventProperties

export type IdentifyEvent = SegmentEventDefinition<
  'identify',
  {
    traits: UserTraits
  }
>

export type TrackEvent = SegmentEventDefinition<
  'track',
  {
    event: string
    properties?: Record<string, unknown>
  }
>

export type PageEvent = SegmentEventDefinition<
  'page',
  {
    properties: {
      path: string
      referrer?: string
      search?: string
      title: string
      url: string
    }
  }
>

export type SegmentEvent = IdentifyEvent | TrackEvent | PageEvent
