import { z } from "zod"

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

export const expenseItemFormSchema = z.object({
    item_type: z.string().min(1, "Item type is required").max(255, "Item type cannot exceed 255 characters"),
    item_name: z.string().min(1, "Item name is required").max(255, "Item name cannot exceed 255 characters"),
    sku: z.string().min(1, "SKU is required").max(255, "SKU cannot exceed 255 characters"),
    item_code: z.string().optional(),
    description: z.string().optional(),
    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"),
    // Purchase
    purchase_information: z.boolean().default(true),
    purchase_price: z.coerce.number().min(0).optional(),
    purchase_chart_of_account: z.string().optional(),
    purchase_preferred_vendor: relationFieldSchema,
    // Sales
    sales_information: z.boolean().default(false),
    selling_price: z.coerce.number().min(0).optional(),
    sales_chart_of_account: z.string().optional(),
    // Status
    is_active: z.boolean().default(true),
})

export type ExpenseItemFormValues = z.infer<typeof expenseItemFormSchema>
