import { z } from "astro:content";

export const GroupViewSchema = z.object({
    type: z.literal("GROUP"),
    groups: z.array(z.number()),
});

export type GroupViewConfig = z.infer<typeof GroupViewSchema>;

export const EleminationViewSchema = z.object({
    type: z.literal("ELEMINATION"),
    finalFight: z.number(),
});

export type EleminationViewConfig = z.infer<typeof EleminationViewSchema>;

// Double elimination config: needs final fight (grand final) and entry fights for winners & losers brackets
export const DoubleEleminationViewSchema = z.object({
    type: z.literal("DOUBLE_ELEMINATION"),
    winnersFinalFight: z.number(), // Final fight of winners bracket (feeds into grand final)
    losersFinalFight: z.number(), // Final fight of losers bracket (feeds into grand final)
    grandFinalFight: z.number(), // Grand final fight id
});

export type DoubleEleminationViewConfig = z.infer<typeof DoubleEleminationViewSchema>;

export const EventViewConfigSchema = z.record(
    z.object({
        name: z.string(),
        view: z.discriminatedUnion("type", [GroupViewSchema, EleminationViewSchema, DoubleEleminationViewSchema]),
    })
);

export type EventViewConfig = z.infer<typeof EventViewConfigSchema>;
