import type { Weekday } from '@core/racing/domain/types/Weekday';

export type SerializedLeagueVisibility = 'ranked' | 'unranked';

export type SerializedLeagueStewardingDecisionMode =
  | 'admin_only'
  | 'steward_decides'
  | 'steward_vote'
  | 'member_vote'
  | 'steward_veto'
  | 'member_veto';

export type SerializedLeagueStewardingSettings = {
  decisionMode: SerializedLeagueStewardingDecisionMode;
  requiredVotes?: number;
  requireDefense?: boolean;
  defenseTimeLimit?: number;
  voteTimeLimit?: number;
  protestDeadlineHours?: number;
  stewardingClosesHours?: number;
  notifyAccusedOnProtest?: boolean;
  notifyOnVoteRequired?: boolean;
};

export type SerializedLeagueCustomPoints = Record<string, number>;

export type SerializedLeagueSettings = {
  pointsSystem: 'f1-2024' | 'indycar' | 'custom';
  sessionDuration?: number;
  qualifyingFormat?: 'single-lap' | 'open';
  customPoints?: SerializedLeagueCustomPoints;
  maxDrivers?: number;
  stewarding?: SerializedLeagueStewardingSettings;
  visibility?: SerializedLeagueVisibility;
};

export type SerializedSeasonWeeklyRecurrence = {
  kind: 'weekly';
  weekdays: Weekday[];
};

export type SerializedSeasonEveryNWeeksRecurrence = {
  kind: 'everyNWeeks';
  intervalWeeks: number;
  weekdays: Weekday[];
};

export type SerializedSeasonMonthlyNthWeekdayRecurrence = {
  kind: 'monthlyNthWeekday';
  ordinal: 1 | 2 | 3 | 4;
  weekday: Weekday;
};

export type SerializedSeasonRecurrence =
  | SerializedSeasonWeeklyRecurrence
  | SerializedSeasonEveryNWeeksRecurrence
  | SerializedSeasonMonthlyNthWeekdayRecurrence;

export type SerializedSeasonSchedule = {
  startDate: string;
  timeOfDay: string;
  timezoneId: string;
  recurrence: SerializedSeasonRecurrence;
  plannedRounds: number;
};

export type SerializedSeasonScoringConfig = {
  scoringPresetId: string;
  customScoringEnabled?: boolean;
};

export type SerializedSeasonDropPolicy = {
  strategy: 'none' | 'bestNResults' | 'dropWorstN';
  n?: number;
};

export type SerializedSeasonStewardingConfig = {
  decisionMode: SerializedLeagueStewardingDecisionMode;
  requiredVotes?: number;
  requireDefense: boolean;
  defenseTimeLimit: number;
  voteTimeLimit: number;
  protestDeadlineHours: number;
  stewardingClosesHours: number;
  notifyAccusedOnProtest: boolean;
  notifyOnVoteRequired: boolean;
};