import { type LonLatPoint } from '../../utils/projection'
import { type GameAudioConfig } from '../audio/audioConfig'
import {
  type ContentCardCtaConfig,
  type ContentCardCtaConfigOverride,
  type ContentCardTemplate,
} from '../experience/contentCard'
import { type H5ExperiencePresentation } from '../experience/h5Experience'

export type GameMode = 'classic-sequential' | 'score-o'
export type GameControlKind = 'start' | 'control' | 'finish'
export type PunchPolicyType = 'enter' | 'enter-confirm'

export interface GameContentExperienceConfig {
  type: 'native' | 'h5'
  url: string | null
  bridge: string
  fallback: 'native'
  presentation: H5ExperiencePresentation
}

export interface GameContentExperienceConfigOverride {
  type?: 'native' | 'h5'
  url?: string
  bridge?: string
  fallback?: 'native'
  presentation?: H5ExperiencePresentation
}

export interface GameControlDisplayContent {
  template: ContentCardTemplate
  title: string
  body: string
  autoPopup: boolean
  once: boolean
  priority: number
  clickTitle: string | null
  clickBody: string | null
  ctas: ContentCardCtaConfig[]
  contentExperience: GameContentExperienceConfig | null
  clickExperience: GameContentExperienceConfig | null
}

export interface GameControlDisplayContentOverride {
  template?: ContentCardTemplate
  title?: string
  body?: string
  autoPopup?: boolean
  once?: boolean
  priority?: number
  clickTitle?: string
  clickBody?: string
  ctas?: ContentCardCtaConfigOverride[]
  contentExperience?: GameContentExperienceConfigOverride
  clickExperience?: GameContentExperienceConfigOverride
}

export interface GameControl {
  id: string
  code: string
  label: string
  kind: GameControlKind
  point: LonLatPoint
  sequence: number | null
  score: number | null
  displayContent: GameControlDisplayContent | null
}

export interface GameDefinition {
  id: string
  mode: GameMode
  title: string
  controlRadiusMeters: number
  sessionCloseAfterMs: number
  sessionCloseWarningMs: number
  minCompletedControlsBeforeFinish: number
  punchRadiusMeters: number
  punchPolicy: PunchPolicyType
  requiresFocusSelection: boolean
  skipEnabled: boolean
  skipRadiusMeters: number
  skipRequiresConfirm: boolean
  controls: GameControl[]
  autoFinishOnLastControl: boolean
  audioConfig?: GameAudioConfig
}
