There are two schemes
they are in different files
You can somehow combine it according to the condition that if the isSurname field is selected, make the prevName/prevSurname fields mandatory and vice versa, or combine it according to the condition (I was looking in the direction of refine)
const A = z.object({
name: z.string(),
surname: z.string(),
});
const B = z.object({
isSurname: z.boolean(),
prevName: z.string(),
prevSurname: z.string(),
});
A.merge(B)