import { z } from 'zod'
import type { Division } from '~/models/division'

const DivisionSchema = z.object({
  code: z.string({ required_error: 'Kode harus diisi' }).min(1, 'Kode minimum 1 karakter'),
  name: z.string({ required_error: 'Nama harus diisi' }).min(1, 'Nama minimum 1 karakter'),
  parent_id: z.union([
    z.string({ required_error: 'Divisi Induk harus diisi' }),
    z.number({ required_error: 'Divisi Induk harus diisi' })
  ]).optional().nullable(),
})

type DivisionFormData = z.infer<typeof DivisionSchema> & Partial<Division>

export { DivisionSchema }
export type { DivisionFormData }
