/**
 * Timing Configuration
 * 
 * Business logic configuration for scoring preset timings
 */

export interface Timings {
  practiceMinutes?: number;
  qualifyingMinutes?: number;
  sprintRaceMinutes?: number;
  mainRaceMinutes?: number;
  sessionCount?: number;
  [key: string]: unknown;
}

export interface TimingConfigData {
  practiceMinutes: number;
  qualifyingMinutes: number;
  sprintRaceMinutes: number;
  mainRaceMinutes: number;
  sessionCount: number;
}

export const timingConfig: Record<string, TimingConfigData> = {
  'sprint-main-driver': {
    practiceMinutes: 20,
    qualifyingMinutes: 30,
    sprintRaceMinutes: 20,
    mainRaceMinutes: 40,
    sessionCount: 2,
  },
  'endurance-main-driver': {
    practiceMinutes: 30,
    qualifyingMinutes: 20,
    sprintRaceMinutes: 0,
    mainRaceMinutes: 120,
    sessionCount: 1,
  },
} as const;

export const applyTimingConfig = (patternId: string, currentTimings: Timings): Timings => {
  const config = timingConfig[patternId];
  if (!config) return currentTimings;

  return {
    ...currentTimings,
    practiceMinutes: currentTimings.practiceMinutes ?? config.practiceMinutes,
    qualifyingMinutes: currentTimings.qualifyingMinutes ?? config.qualifyingMinutes,
    sprintRaceMinutes: currentTimings.sprintRaceMinutes ?? config.sprintRaceMinutes,
    mainRaceMinutes: currentTimings.mainRaceMinutes ?? config.mainRaceMinutes,
    sessionCount: config.sessionCount,
  };
};