import { z } from "zod" import { vxlanServersSchema } from "@/lib/vxlan-response" export const recursiveServersSchema = vxlanServersSchema export const recursiveRowSchema = z.object({ id: z.string().trim().min(1), dstAddress: z.string().trim().min(1), gateway: z.string().trim().min(1), distance: z.number().int().min(0).max(255), scope: z.number().int().min(0).max(255).nullable(), targetScope: z.number().int().min(0).max(255).nullable(), routingTable: z.string().trim().min(1), checkGateway: z.string(), comment: z.string(), disabled: z.boolean(), country: z.string(), }) const rows = z.array(recursiveRowSchema).refine(rows => new Set(rows.map(row => row.id)).size === rows.length) export const recursiveReadSchema = z.object({ serverId: z.number().int().positive(), routes: rows, live: z.boolean(), stale: z.boolean(), error: z.string().optional(), }).refine(data => data.live !== data.stale) export const recursiveReceiptSchema = z.object({ ok: z.literal(true), serverId: z.number().int().positive(), routes: rows, pushedRoutes: z.number().int().nonnegative(), }).refine(data => data.pushedRoutes === data.routes.length) export const recursiveGatewaysSchema = z.object({ serverId: z.number().int().positive(), gateways: z.array(z.object({ id: z.string().min(1), name: z.string(), ip: z.string().min(1), status: z.enum(["active", "inactive", "unknown"]), })).refine(rows => new Set(rows.map(row => row.id)).size === rows.length), }) export type RecursiveRouteRow = z.infer