export function validateBillData(data) {
  const errors = {};
  
  if (!data.vendor_name || data.vendor_name.trim().length === 0) {
    errors.vendor_name = "Vendor name is required";
  }

  if (data.amount === undefined || data.amount === null || isNaN(parseFloat(data.amount)) || parseFloat(data.amount) <= 0) {
    errors.amount = "Valid total amount is required";
  }

  if (!data.bill_date) {
    errors.bill_date = "Bill date is required";
  }

  // Optional: check for line items if your logic requires at least one
  // if (!data.line_items || data.line_items.length === 0) {
  //   errors.line_items = "At least one line item is recommended";
  // }

  // Check line items validity if they exist
  if (data.line_items && data.line_items.length > 0) {
      data.line_items.forEach((item, index) => {
          if (!item.description) {
              errors[`line_item_${index}_desc`] = "Description missing";
          }
          if (!item.total || isNaN(item.total)) {
               errors[`line_item_${index}_total`] = "Total amount missing";
          }
      });
  }

  return {
    isValid: Object.keys(errors).length === 0,
    errors
  };
}