import Fuse from "fuse.js";
export default async function listPhoneNumbers(db, { method, next, limit, orderBy, orderDirection, query }) {
  var _a, _b;
  const collectionPath = "phoneNumbers";
  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 phoneNumbers = (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(phoneNumbers, {
      keys: ["name"],
    });
    phoneNumbers = await fuse.search(query).map((result) => result === null || result === void 0 ? void 0 : result.item);
  }
  if (!phoneNumbers)
    return null;
  return phoneNumbers;
}
//# sourceMappingURL=listPhoneNumbers.js.map