import { z } from 'zod'

const PersonFamilySchema = z.object({
  relation: z.enum(['mother', 'father', 'guardian', 'emergency_contact']),
  name: z
    .string({
      required_error: 'Mohon lengkapi nama',
    })
    .min(1, 'Mohon lengkapi nama'),
  education: z
    .string({
      required_error: 'Mohon pilih pendidikan',
    })
    .min(1, 'Mohon pilih pendidikan'),
  occupation: z.string().optional(),
})

const PersonFamiliesSchema = z.discriminatedUnion('shareFamilyData', [
  z.object({
    shareFamilyData: z.literal('0'),
    families: z.array(PersonFamilySchema).optional().default([]),
  }),
  z.object({
    shareFamilyData: z.literal('1'),
    families: z.array(PersonFamilySchema).min(1, 'Minimal 1 kontak keluarga'),
  }),
])

type PersonFamilyFormData = z.infer<typeof PersonFamilySchema>
type PersonFamiliesFormData = z.infer<typeof PersonFamiliesSchema>

export { PersonFamilySchema, PersonFamiliesSchema }
export type { PersonFamilyFormData, PersonFamiliesFormData }
