import { z } from 'zod'; import { CopyIdSchema } from './install.ts'; export const LocalUserIdSchema = z.string().regex(/^\d+$/); export const SaveKeysSchema = z.object({ copyId: CopyIdSchema, userId: LocalUserIdSchema }); export const CurrencyEditsSchema = z.object({ silverLions: z.number().int().nonnegative().optional(), goldenEagles: z.number().int().min(0).max(0x7fffffff).optional(), gjnCents: z.number().int().nonnegative().optional(), freeRp: z.number().int().nonnegative().optional(), }); const SaveSummarySchema = z.object({ userId: LocalUserIdSchema, login: z.string(), nick: z.string(), created: z.string(), currencies: z.object({ silverLions: z.number(), goldenEagles: z.number(), gjnCents: z.number(), freeRp: z.number(), }).nullable(), vehicleCount: z.number().int().nonnegative(), battleCount: z.number().int().nonnegative(), lastBattle: z.number().nullable(), premiumDays: z.number(), }); export const SaveListSchema = z.object({ saves: z.array(SaveSummarySchema), current: LocalUserIdSchema.nullable() }); export const SaveDetailsSchema = z.object({ save: SaveSummarySchema, battles: z.array(z.object({ id: z.string(), time: z.number(), won: z.boolean().nullable(), mission: z.string(), mode: z.string(), vehicles: z.array(z.string()), silverLions: z.number(), researchPoints: z.number(), })), owned: z.array(z.string()), research: z.array(z.object({ name: z.string(), points: z.number() })), }); export const SaveRegistrationSchema = z.object({ copyId: CopyIdSchema, login: z.string(), password: z.string(), nick: z.string(), }); export const SaveTransferSchema = SaveRegistrationSchema.extend({ source: z.discriminatedUnion('kind', [ z.object({ kind: z.literal('save'), copyId: CopyIdSchema, userId: LocalUserIdSchema }), z.object({ kind: z.literal('file'), path: z.string().min(1) }), ]), }); export const SaveBackupNameSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z\.(manual|launch|restore)\.[0-9a-f-]{36}\.zip$/); export const SaveBackupSchema = z.object({ name: SaveBackupNameSchema, createdAt: z.string(), type: z.enum(['manual', 'launch', 'restore']), size: z.number().int().nonnegative(), }); export type SaveTransfer = z.output; export type SaveBackup = z.output; export type SaveList = z.output; export type SaveDetails = z.output; export type CurrencyEdits = z.output; export type SaveRegistration = z.output;