"use strict";

exports.__esModule = true;
exports.createBackend = createBackend;
exports.createItems = createItems;
exports.itemsSelectionAPIHttpClientMocks = void 0;
var _backend = require("../testkit/backend");
var _chance = require("chance");
var _http = require("@wix/bex-utils/@wix/ambassador-items-selection-spi-host-v1-provider/http");
var _builders = require("@wix/bex-utils/@wix/ambassador-items-selection-spi-host-v1-provider/builders");
function createItems(chance) {
  return ({
    ...overrides
  } = {}) => (0, _builders.aItem)({
    id: chance.guid(),
    ...overrides
  });
}
function createBackend() {
  const chance = new _chance.Chance();
  return new _backend.InMemoryBackend({
    total: 10,
    paginationMode: 'offset',
    delay: {
      min: 100,
      max: 2000
    },
    createOne: () => (0, _builders.aItem)({
      id: chance.guid(),
      name: chance.name(),
      description: chance.sentence({
        words: 5
      })
    }),
    orderBy: query => {
      return [...(query.sort ?? [])];
    },
    itemKey: item => item.id
  });
}
const itemsSelectionAPIHttpClientMocks = whenRequest => {
  const itemsSelectionBackend = createBackend();
  return [whenRequest(_http.queryItems).reply(200, async () => {
    return itemsSelectionBackend.fetchData({
      limit: 10
    }).then(({
      items
    }) => {
      return {
        items
      };
    });
  }).persist()];
};
exports.itemsSelectionAPIHttpClientMocks = itemsSelectionAPIHttpClientMocks;
//# sourceMappingURL=ItemsSelectionMocks.js.map