Issue in making required field optional in ZOD? would you please tell me where is the issue in below code?

const schema = z.object({
workType: z.string().min(1, { message: “Please select work type” }),
workSubType: z.string().min(1, { message: “Please select work sub type” }),
workTypeDescriptions: z.string().min(1, { message: “Please select description” }),
radioButtonSelection: z.enum([“Yes”, “No”], {errorMap: () => ({ message: “Please select an option” })}),
policyNumber: z.string().refine((value , data) => {
if (data.radioButtonSelection === “Yes”) {
return typeof value === ‘string’ && value.length >= 7;
}
return true;
}, {message: ‘please enter policy number’, path:[‘policyNumber’]}).optional(),
});