import state from "../../store";
export default async function addFlow(db, { tags, userId, locationId, name, successTemplate, errorTemplate, showProgress, paths, }) {
  var _a, _b, _c;
  const id = db.getDocumentId();
  const Data = {
    id,
    tags,
    successTemplate,
    errorTemplate,
    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,
    user: userId ? db.document("users", userId) : null,
    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;
}
