import Fuse from "fuse.js";
import pick from "../../helpers/pick";
export default async function listExhausts(db, { data: { limit, next, query, method, orderBy, orderDirection } }, filterKeys = [
  "inletTemperature",
  "inletHumidity",
  "inletGrainsPerPound",
  "outletTemperature",
  "outletHumidity",
  "outletGrainsPerPound",
  "createdAt",
  "updatedAt"
]) {
  var _a, _b;
  const collectionPath = "exhausts";
  const where = [];
  if (method)
    where.push({
      key: "method",
      conditional: "==",
      value: method
    });
  const startAfter = (next === null || next === void 0 ? void 0 : next.length) && (await db.getDocument(collectionPath, next));
  let exhausts = (await db.list(collectionPath, where, `${orderBy || "createdAt"}:${orderDirection || "desc"}`, limit, startAfter && {
    startAfter: (_b = (_a = startAfter === null || startAfter === void 0 ? void 0 : startAfter.data) === null || _a === void 0 ? void 0 : _a.call(startAfter)) === null || _b === void 0 ? void 0 : _b.createdAt,
  }));
  if (query === null || query === void 0 ? void 0 : query.length) {
    const fuse = new Fuse(exhausts, {
      keys: ["name"],
    });
    exhausts = await fuse.search(query).map((result) => result === null || result === void 0 ? void 0 : result.item);
  }
  if (!exhausts)
    return null;
  return exhausts.map((service) => filterKeys ? pick(service, filterKeys) : service);
}
//# sourceMappingURL=listExhausts.js.map