export type ScoringPresetTimings = {
  practiceMinutes?: number;
  qualifyingMinutes?: number;
  sprintRaceMinutes?: number;
  mainRaceMinutes?: number;
  sessionCount?: number;
  roundsPlanned?: number;
  raceDayOfWeek?: number;
  raceTimeUtc?: string;
};

/**
 * Apply high-level scoring preset semantics to league/session timings.
 *
 * This encapsulates the mapping between logical scoring presets (sprint, endurance, etc.)
 * and their default timing configuration so that UI layers do not need to duplicate
 * or interpret preset IDs directly.
 */
export function applyScoringPresetToTimings(
  patternId: string,
  currentTimings: ScoringPresetTimings,
): ScoringPresetTimings {
  const lowerPresetId = patternId.toLowerCase();
  let updatedTimings: ScoringPresetTimings = { ...currentTimings };

  if (lowerPresetId.includes('sprint') || lowerPresetId.includes('double')) {
    updatedTimings = {
      ...updatedTimings,
      practiceMinutes: 15,
      qualifyingMinutes: 20,
      sprintRaceMinutes: 20,
      mainRaceMinutes: 35,
      sessionCount: 2,
    };
  } else if (lowerPresetId.includes('endurance') || lowerPresetId.includes('long')) {
    updatedTimings = {
      ...updatedTimings,
      practiceMinutes: 30,
      qualifyingMinutes: 30,
      mainRaceMinutes: 90,
      sessionCount: 1,
    };
    delete (updatedTimings as { sprintRaceMinutes?: number }).sprintRaceMinutes;
  } else {
    updatedTimings = {
      ...updatedTimings,
      practiceMinutes: 20,
      qualifyingMinutes: 30,
      mainRaceMinutes: 40,
      sessionCount: 1,
    };
    delete (updatedTimings as { sprintRaceMinutes?: number }).sprintRaceMinutes;
  }

  return updatedTimings;
}
