191 lines
4.1 KiB
TypeScript
191 lines
4.1 KiB
TypeScript
import type {
|
|
CompetitionFactId,
|
|
GameId,
|
|
GameSlotId,
|
|
SeriesId,
|
|
TeamId,
|
|
} from "./ids.js";
|
|
|
|
export type IsoDateTime = string;
|
|
export type SeriesSlot = "A" | "B";
|
|
export type SeriesStageType =
|
|
| "pair"
|
|
| "round-robin"
|
|
| "upper"
|
|
| "lower"
|
|
| "grand-final"
|
|
| "reset-final";
|
|
|
|
export interface FirstToSeriesRule {
|
|
type: "first-to";
|
|
winsRequired: number;
|
|
maxGames: number;
|
|
}
|
|
|
|
export interface FixedGamesSeriesRule {
|
|
type: "fixed-games";
|
|
gameCount: number;
|
|
drawPolicy: "allow" | "tiebreak-required";
|
|
}
|
|
|
|
export type SeriesRule = FirstToSeriesRule | FixedGamesSeriesRule;
|
|
|
|
export type ParticipantSource =
|
|
| { type: "team"; teamId: TeamId }
|
|
| { type: "seed"; seedNumber: number }
|
|
| {
|
|
type: "series-outcome";
|
|
seriesId: SeriesId;
|
|
select: "winner" | "loser";
|
|
}
|
|
| {
|
|
type: "series-slot";
|
|
seriesId: SeriesId;
|
|
slot: SeriesSlot;
|
|
};
|
|
|
|
export interface SeriesStage {
|
|
type: SeriesStageType;
|
|
roundNumber?: number;
|
|
displayOrder: number;
|
|
}
|
|
|
|
export interface SeriesSlotDefinition {
|
|
position: SeriesSlot;
|
|
source: ParticipantSource;
|
|
}
|
|
|
|
export interface GameSlotDefinition {
|
|
id: GameSlotId;
|
|
seriesId: SeriesId;
|
|
ordinal: number;
|
|
}
|
|
|
|
export interface GrandFinalResetActivationRule {
|
|
type: "grand-final-reset-required";
|
|
grandFinalSeriesId: SeriesId;
|
|
}
|
|
|
|
export type SeriesActivationRule = GrandFinalResetActivationRule;
|
|
|
|
export interface SeriesSchedule {
|
|
date: string;
|
|
time: string | null;
|
|
timeZone: "Asia/Seoul";
|
|
}
|
|
|
|
export interface SeriesDefinition {
|
|
id: SeriesId;
|
|
code?: string;
|
|
stage: SeriesStage;
|
|
slots: [SeriesSlotDefinition, SeriesSlotDefinition];
|
|
rule: SeriesRule;
|
|
schedule?: SeriesSchedule;
|
|
activation?: SeriesActivationRule;
|
|
gameSlots: GameSlotDefinition[];
|
|
}
|
|
|
|
export interface PendingSeriesEntry {
|
|
slot: SeriesSlot;
|
|
teamId: TeamId | null;
|
|
gameWins: 0;
|
|
}
|
|
|
|
export interface ResolvedSeriesEntry {
|
|
slot: SeriesSlot;
|
|
teamId: TeamId;
|
|
gameWins: number;
|
|
}
|
|
|
|
export interface ReadySeriesEntry extends ResolvedSeriesEntry {
|
|
gameWins: 0;
|
|
}
|
|
|
|
export type PendingSeriesEntries = [PendingSeriesEntry, PendingSeriesEntry];
|
|
export type ReadySeriesEntries = [ReadySeriesEntry, ReadySeriesEntry];
|
|
export type ResolvedSeriesEntries = [
|
|
ResolvedSeriesEntry,
|
|
ResolvedSeriesEntry,
|
|
];
|
|
|
|
interface SeriesProjectionBase {
|
|
seriesId: SeriesId;
|
|
code?: string;
|
|
stage: SeriesStage;
|
|
rule: SeriesRule;
|
|
schedule?: SeriesSchedule;
|
|
}
|
|
|
|
export interface PlayedSeriesOutcome {
|
|
type: "played";
|
|
winnerTeamId: TeamId;
|
|
loserTeamId: TeamId;
|
|
decidedByGameIds: GameId[];
|
|
completedAt: IsoDateTime;
|
|
}
|
|
|
|
export interface AdjudicatedSeriesOutcome {
|
|
type: "walkover" | "forfeit" | "administrative";
|
|
winnerTeamId: TeamId;
|
|
loserTeamId: TeamId;
|
|
decisionFactId: CompetitionFactId;
|
|
completedAt: IsoDateTime;
|
|
}
|
|
|
|
export type DrawDecisionBasis =
|
|
| { type: "played"; decidedByGameIds: GameId[] }
|
|
| { type: "administrative"; decisionFactId: CompetitionFactId };
|
|
|
|
export interface DrawSeriesOutcome {
|
|
type: "draw";
|
|
basis: DrawDecisionBasis;
|
|
completedAt: IsoDateTime;
|
|
}
|
|
|
|
export type SeriesOutcome =
|
|
| PlayedSeriesOutcome
|
|
| AdjudicatedSeriesOutcome
|
|
| DrawSeriesOutcome;
|
|
|
|
export interface InactiveSeriesProjection extends SeriesProjectionBase {
|
|
status: "inactive";
|
|
entries: PendingSeriesEntries;
|
|
leaderTeamId?: never;
|
|
outcome?: never;
|
|
}
|
|
|
|
export interface WaitingSeriesProjection extends SeriesProjectionBase {
|
|
status: "waiting";
|
|
entries: PendingSeriesEntries;
|
|
leaderTeamId?: never;
|
|
outcome?: never;
|
|
}
|
|
|
|
export interface ReadySeriesProjection extends SeriesProjectionBase {
|
|
status: "ready";
|
|
entries: ReadySeriesEntries;
|
|
leaderTeamId?: never;
|
|
outcome?: never;
|
|
}
|
|
|
|
export interface InProgressSeriesProjection extends SeriesProjectionBase {
|
|
status: "in-progress";
|
|
entries: ResolvedSeriesEntries;
|
|
leaderTeamId?: TeamId;
|
|
outcome?: never;
|
|
}
|
|
|
|
export interface CompletedSeriesProjection extends SeriesProjectionBase {
|
|
status: "completed";
|
|
entries: ResolvedSeriesEntries;
|
|
leaderTeamId?: never;
|
|
outcome: SeriesOutcome;
|
|
}
|
|
|
|
export type SeriesProjection =
|
|
| InactiveSeriesProjection
|
|
| WaitingSeriesProjection
|
|
| ReadySeriesProjection
|
|
| InProgressSeriesProjection
|
|
| CompletedSeriesProjection;
|