import { z } from 'zod'
import type { Unit } from '~/models/unit'

const UnitSchema = 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'),
  installation_id: z
    .union([
      z.string({ required_error: 'Instalasi harus diisi' }),
      z.number({ required_error: 'Instalasi harus diisi' }),
    ])
    .optional()
    .nullable(),
})

type UnitFormData = z.infer<typeof UnitSchema> & Partial<Unit>

export { UnitSchema }
export type { UnitFormData }
