import { z } from "zod"

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

export const partFormSchema = z.object({
    shop_type: relationFieldSchema.refine((val) => !!val?.value, "Shop type is required"),
    category: relationFieldSchema.refine((val) => !!val?.value, "Category is required"),
    unit_type: relationFieldSchema.refine((val) => !!val?.value, "Unit type is required"),
    department: relationFieldSchema.refine((val) => !!val?.value, "Department is required"),
    title: z.string().min(1, "Title is required"),
    sku: z.string().min(1, "SKU is required"),
    description: z.string().optional(),
    selling_price: z.coerce.number().min(0).optional(),
    purchase_price: z.coerce.number().min(0).optional(),
    opening_stock: z.coerce.number().min(0).optional(),
})

export type PartFormValues = z.infer<typeof partFormSchema>
