import { type GameMode } from './gameDefinition'

export interface GameModeDefaults {
  sessionCloseAfterMs: number
  sessionCloseWarningMs: number
  minCompletedControlsBeforeFinish: number
  requiresFocusSelection: boolean
  skipEnabled: boolean
  skipRequiresConfirm: boolean
  autoFinishOnLastControl: boolean
  defaultControlScore: number
}

const GAME_MODE_DEFAULTS: Record<GameMode, GameModeDefaults> = {
  'classic-sequential': {
    sessionCloseAfterMs: 2 * 60 * 60 * 1000,
    sessionCloseWarningMs: 10 * 60 * 1000,
    minCompletedControlsBeforeFinish: 0,
    requiresFocusSelection: false,
    skipEnabled: true,
    skipRequiresConfirm: true,
    autoFinishOnLastControl: false,
    defaultControlScore: 1,
  },
  'score-o': {
    sessionCloseAfterMs: 2 * 60 * 60 * 1000,
    sessionCloseWarningMs: 10 * 60 * 1000,
    minCompletedControlsBeforeFinish: 1,
    requiresFocusSelection: false,
    skipEnabled: false,
    skipRequiresConfirm: true,
    autoFinishOnLastControl: false,
    defaultControlScore: 10,
  },
}

export function getGameModeDefaults(mode: GameMode): GameModeDefaults {
  return GAME_MODE_DEFAULTS[mode]
}

export function getDefaultSkipRadiusMeters(mode: GameMode, punchRadiusMeters: number): number {
  if (mode === 'classic-sequential') {
    return punchRadiusMeters * 2
  }

  return 30
}

export function resolveDefaultControlScore(mode: GameMode, configuredDefaultScore: number | null): number {
  if (typeof configuredDefaultScore === 'number') {
    return configuredDefaultScore
  }

  return getGameModeDefaults(mode).defaultControlScore
}
