import state from "../../store";
export default async function editScopeService(db, { jobId, siteId, id, amount, price, quantity }) {
  var _a, _b;
  const collectionPath = siteId
    ? `/sites/${siteId}/services`
    : `/jobs/${jobId}/services`;
  const service = state.services.find((service) => (service === null || service === void 0 ? void 0 : service.id) === id);
  const data = {
    amount,
    quantity,
    price: price || ((_a = service === null || service === void 0 ? void 0 : service.prices) === null || _a === void 0 ? void 0 : _a.default) || 0,
    total: parseFloat(`${amount || 0}`) *
      parseFloat(`${quantity || 1}`) *
      parseFloat(`${price || ((_b = service === null || service === void 0 ? void 0 : service.prices) === null || _b === void 0 ? void 0 : _b.default) || 0}`),
    createdAt: new Date(),
    service: db.document("services", id),
  };
  const scopeService = await db.update(collectionPath, id, data);
  return scopeService;
}
//# sourceMappingURL=editScopeService.js.map