import { z } from "zod"; export const deviceSourceValues = [ "fritzbox", "dns", "http", "https", "portscan", "manual", "plugin", ] as const; export const DeviceSourceSchema = z.enum(deviceSourceValues); export const DeviceCreateSchema = z.object({ hostname: z.string().min(1, "hostname darf nicht leer sein"), ip: z.string().min(1, "ip darf nicht leer sein"), mac: z.string().optional(), manufacturer: z.string().optional(), model: z.string().optional(), online: z.boolean().optional(), source: DeviceSourceSchema.optional(), }); export type DeviceCreateInput = z.infer; export const DeviceUpdateSchema = DeviceCreateSchema.partial(); export type DeviceUpdateInput = z.infer; export const ServiceCreateSchema = z.object({ deviceId: z.string().min(1, "deviceId darf nicht leer sein"), displayName: z.string().min(1, "displayName darf nicht leer sein"), hostname: z.string().min(1, "hostname darf nicht leer sein"), url: z.string().url("url muss eine gültige URL sein"), https: z.boolean().optional(), port: z.number().int().min(1).max(65535), category: z.string().optional(), icon: z.string().optional(), favicon: z.string().optional(), description: z.string().optional(), favorite: z.boolean().optional(), alias: z.array(z.string()).optional(), order: z.number().optional(), visible: z.boolean().optional(), }); export type ServiceCreateInput = z.infer; export const ServiceUpdateSchema = ServiceCreateSchema.omit({ deviceId: true, }).partial(); export type ServiceUpdateInput = z.infer; /** Für Drag & Drop: neue Reihenfolge mehrerer Dienste auf einmal setzen. */ export const ServiceReorderSchema = z .array( z.object({ id: z.string().min(1), order: z.number(), }) ) .min(1, "mindestens ein Eintrag erforderlich"); export type ServiceReorderInput = z.infer; export const CategoryCreateSchema = z.object({ name: z.string().min(1, "name darf nicht leer sein"), }); export type CategoryCreateInput = z.infer; export const CategoryUpdateSchema = CategoryCreateSchema.partial(); export type CategoryUpdateInput = z.infer; /** Für Drag & Drop: neue Reihenfolge mehrerer Kategorien auf einmal setzen. */ export const CategoryReorderSchema = z .array( z.object({ id: z.string().min(1), order: z.number(), }) ) .min(1, "mindestens ein Eintrag erforderlich"); export type CategoryReorderInput = z.infer;