export default function updateJobAmounts(job) {
  let amountBilled = 0;
  // Calculate totals for general job
  for (const generalService of (job === null || job === void 0 ? void 0 : job.services) || []) {
    amountBilled = amountBilled + ((generalService === null || generalService === void 0 ? void 0 : generalService.total) || 0);
  }
  // Calculate totals for sites
  for (const site of (job === null || job === void 0 ? void 0 : job.sites) || []) {
    for (const scopeService of (site === null || site === void 0 ? void 0 : site.services) || []) {
      amountBilled = amountBilled + ((scopeService === null || scopeService === void 0 ? void 0 : scopeService.total) || 0);
    }
  }
  let amountPaid = 0;
  for (const payment of (job === null || job === void 0 ? void 0 : job.payments) || []) {
    amountPaid = amountPaid + ((payment === null || payment === void 0 ? void 0 : payment.amount) || 0);
  }
  const amountOwed = (amountBilled || 0) - (amountPaid || 0);
  return {
    amountBilled,
    amountPaid,
    amountOwed,
    updatedAt: new Date(),
  };
}
