import { z } from "zod"

const relationFieldSchema = z
    .object({ value: z.string(), label: z.string() })
    .nullable()

const inspectionFormSchema = z.object({
    customer: relationFieldSchema.refine((val) => !!val?.value, "Customer is required"),
    vehicle: relationFieldSchema.refine((val) => !!val?.value, "Vehicle is required"),
    department: relationFieldSchema.refine((val) => !!val?.value, "Department is required"),
    inspection_category: relationFieldSchema.refine((val) => !!val?.value, "Inspection category is required"),
    employee: relationFieldSchema.refine((val) => !!val?.value, "Employee is required"),
    job_card: relationFieldSchema.optional(),
    labor_rate: relationFieldSchema.optional(),
    title: z.string().min(1, "Title is required").max(100, "Title cannot exceed 100 characters"),
    order_number: z.string().min(1, "Order number is required").max(100, "Order number cannot exceed 100 characters"),
    date: z.string().min(1, "Date is required"),
    time: z.string().min(1, "Time is required"),
    status: z.string().optional(),
    note: z.string().optional(),
    description: z.string().optional(),
    rate_type: z.string().optional(),
    quantity: z.coerce.number().min(0).optional(),
    rate: z.coerce.number().min(0).optional(),
    working_hours: z.coerce.number().min(0).optional(),
    labor_hours: z.coerce.number().min(0).optional(),
    tax: relationFieldSchema.optional(),
    chart_of_account: z.string().optional(),
})

type InspectionFormValues = z.infer<typeof inspectionFormSchema>

export { inspectionFormSchema, relationFieldSchema }
export type { InspectionFormValues }
