import state from "../../store";
export default async function addFlow(db, { tags, defaultPath, locationId, name, endpoint, successTemplateId, errorTemplateId, showProgress, paths, }) {
  var _a, _b, _c;
  const id = db.getDocumentId();
  const Data = {
    id,
    tags,
    endpoint: endpoint || null,
    successTemplate: successTemplateId
      ? db.document("templates", successTemplateId)
      : null,
    successTemplateId: successTemplateId || null,
    errorTemplate: errorTemplateId
      ? db.document("templates", errorTemplateId)
      : null,
    errorTemplateId: errorTemplateId || null,
    paths,
    name,
    showProgress,
    location: locationId || ((_a = state === null || state === void 0 ? void 0 : state.claims) === null || _a === void 0 ? void 0 : _a.locationId)
      ? db.document("locations", locationId || ((_b = state === null || state === void 0 ? void 0 : state.claims) === null || _b === void 0 ? void 0 : _b.locationId))
      : null,
    defaultPath,
    createdAt: new Date(),
    createdBy: ((_c = state === null || state === void 0 ? void 0 : state.session) === null || _c === void 0 ? void 0 : _c.uid)
      ? db.document("users", state.session.uid)
      : null,
  };
  const addDoc = await db.add("flows", Data, id);
  Data.id = addDoc.id;
  return Data;
}
