import { z } from 'zod'
import type { Infra } from '~/models/infra'

const InfraSchema = 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'),
  infraGroup_code: z.string().min(1, 'Infra Group harus diisi'),
  parent_id: z
    .union([z.string({ required_error: 'Induk harus diisi' }), z.number({ required_error: 'Induk harus diisi' })])
    .optional()
    .nullable(),
  specialist_id: z.union([z.string(), z.number()]).nullable().optional(),
  subspecialist_id: z.union([z.string(), z.number()]).nullable().optional(),
  unit_id: z.union([z.string(), z.number()]).nullable().optional(),
})

type InfraFormData = z.infer<typeof InfraSchema> & Partial<Infra>

export { InfraSchema }
export type { InfraFormData }
