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