Some checks failed
Deploy to Cloudflare Workers / deploy (push) Has been cancelled
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { z } from "zod";
|
|
|
|
export const cupFormatSchema = z.object({
|
|
legs: z.enum(["single", "home_away"]).default("single"),
|
|
third_place_match: z.boolean().default(false),
|
|
seeding: z.enum(["random", "manual"]).default("random"),
|
|
});
|
|
|
|
export const leagueRulesSchema = z.object({
|
|
points_win: z.number().int().min(0).default(3),
|
|
points_draw: z.number().int().min(0).default(1),
|
|
round_robin_format: z.enum(["single", "double"]).default("double"),
|
|
transfer_policy: z.enum(["anytime", "window"]).default("anytime"),
|
|
auto_qualify_count: z.number().int().min(0).default(1),
|
|
strict_availability: z.boolean().default(false),
|
|
result_approval_required: z.boolean().default(true),
|
|
cup_format: cupFormatSchema.default({}),
|
|
});
|
|
|
|
export type LeagueRules = z.infer<typeof leagueRulesSchema>;
|
|
|
|
export const defaultLeagueRules: LeagueRules = {
|
|
points_win: 3,
|
|
points_draw: 1,
|
|
round_robin_format: "double",
|
|
transfer_policy: "anytime",
|
|
auto_qualify_count: 1,
|
|
strict_availability: false,
|
|
result_approval_required: true,
|
|
cup_format: {
|
|
legs: "single",
|
|
third_place_match: false,
|
|
seeding: "random",
|
|
},
|
|
};
|
|
|
|
export function parseLeagueRules(data: unknown): LeagueRules {
|
|
return leagueRulesSchema.parse({ ...defaultLeagueRules, ...(data as object) });
|
|
}
|