import { z } from "zod"

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

const partLineSchema = z.object({
    part: relationFieldSchema,
    quantity: z.coerce.number().min(1, "Quantity must be at least 1"),
    rate: z.coerce.number().min(0, "Rate must be 0 or more"),
})

export const inventoryAdjustmentFormSchema = z.object({
    reference_number: z.string().optional(),
    date: z.string().optional(),
    chart_of_account: z.string().optional(),
    reason: relationFieldSchema,
    notes: z.string().optional(),
    parts: z.array(partLineSchema).min(1, "At least one part is required"),
})

export type InventoryAdjustmentFormValues = z.infer<typeof inventoryAdjustmentFormSchema>
export type PartLineValues = z.infer<typeof partLineSchema>
