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 LocalizedNameSchema = z.object({ en: z.string(), zh: z.string() }); export const SaveAvatarIdSchema = z.string().regex(/^cardicon_[a-z0-9_]+$/); export const SaveAvatarChoicesSchema = z.array(z.object({ id: SaveAvatarIdSchema, name: LocalizedNameSchema, })); export type SaveAvatarChoices = z.output; export const AccountEditsSchema = z.object({ nick: z.string().optional(), premiumDays: z.number().int().nonnegative().optional(), avatar: SaveAvatarIdSchema.optional(), level: z.number().int().nonnegative().optional(), }); export type AccountEdits = z.output; 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(), avatar: z.string(), level: z.number().int().nonnegative().nullable(), 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, maxLevel: z.number().int().positive().nullable(), battles: z.array(z.object({ id: z.string(), time: z.number(), won: z.boolean().nullable(), mission: z.string(), missionName: LocalizedNameSchema, mode: z.string(), vehicles: z.array(z.string()), vehicleNames: z.array(LocalizedNameSchema), 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|import)\.[0-9a-f-]{36}\.zip$/); export const SaveBackupSchema = z.object({ name: SaveBackupNameSchema, createdAt: z.string(), type: z.enum(['manual', 'launch', 'restore', 'import']), size: z.number().int().nonnegative(), }); export const OnlineDataFileNameSchema = z.enum(['global.blk', 'machine.blk', 'storage.blk']); export const OnlineDataSourceSchema = z.object({ accountId: z.string().regex(/^\d+$/), folder: z.string().min(1), files: z.array(OnlineDataFileNameSchema).min(1), updatedAt: z.string(), }); export const SaveOfficialRequestSchema = SaveKeysSchema.extend({ paths: z.array(z.string().min(1)).min(1).max(3), }); export const OfficialImportOptionsSchema = z.object({ importSettings: z.boolean(), unlockVehicles: z.boolean(), equipment: z.enum(['full', 'basic', 'stock']), }); export const OfficialPreviewSchema = z.object({ files: z.array(z.object({ name: z.string(), version: z.number().int() })), presets: z.array(z.object({ country: z.string(), title: z.string(), vehicles: z.array(z.string()) })), vehicles: z.array(z.string()), vehicleNames: z.record(z.string(), LocalizedNameSchema), omitted: z.array(z.string()), }); export const ResearchBranchSchema = z.object({ country: z.string().min(1), type: z.string().min(1) }); export const ResearchOperationSchema = z.enum(['purchase', 'equipment']); export const SaveResearchSchema = z.object({ branches: z.array(ResearchBranchSchema), selected: ResearchBranchSchema.nullable(), vehicles: z.array(z.object({ name: z.string(), rank: z.number(), owned: z.boolean(), points: z.number(), needed: z.number(), })), }); export type ResearchBranch = z.output; export type ResearchOperation = z.output; export type SaveResearch = z.output; export type OnlineDataSource = z.output; export type OfficialPreview = z.output; export type OfficialImportOptions = z.output; 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;