/**
 * Testkit for testing dealer BI events.
 *
 * Provides a singleton-style API similar to biTestkit from @wix/bex-core/bi/testkit.
 * Captures dealer reportEvent HTTP calls and provides utilities to assert on events.
 *
 * @example
 * ```typescript
 * import dealerBITestkit from '../test-utils/DealerBIMock';
 *
 * describe('MyComponent', () => {
 *   const setup = () => {
 *     const driver = new MyDriver({
 *       httpMocks: [
 *         // ... other mocks
 *         dealerBITestkit.httpMock,
 *       ],
 *     });
 *     return { driver };
 *   };
 *
 *   it('sends view event', async () => {
 *     setup();
 *     // ... trigger the view event
 *
 *     expect(dealerBITestkit.view.last()).toEqual(
 *       expect.objectContaining({
 *         offerId: 'offer-1',
 *       }),
 *     );
 *   });
 * });
 * ```
 */
import { whenRequest } from '@wix/yoshi-flow-bm/testkit/http-client';
import { reportEvent } from '@wix/bex-utils/@wix/ambassador-dealer-v1-offer-event/http';
// Re-export EventType for convenience
export { EventType } from '@wix/bex-utils/@wix/ambassador-dealer-v1-offer-event/types';
// Singleton spy to capture all events
const eventsSpy = jest.fn();
// Create HTTP mock once
const httpMock = whenRequest(reportEvent)
    .reply(async (data) => {
    eventsSpy(data);
    return { status: 200, data: {} };
})
    .persist();
const _getAllEventsOfType = (type) => type
    ? eventsSpy.mock.calls
        .filter((call) => call[0]?.event?.type === type)
        .map((call) => call[0])
    : eventsSpy.mock.calls.map((call) => call[0]);
const createEventTypeAccessor = (type) => ({
    all: () => _getAllEventsOfType(type),
    last: () => {
        const events = _getAllEventsOfType(type);
        return events.length > 0 ? events[events.length - 1] : undefined;
    },
    count: () => _getAllEventsOfType(type).length,
});
const dealerBITestkit = {
    httpMock,
    view: createEventTypeAccessor('VIEW'),
    mainCtaClick: createEventTypeAccessor('MAIN_CTA_CLICK'),
    all: _getAllEventsOfType,
    last: () => {
        const events = _getAllEventsOfType();
        return events.length > 0 ? events[events.length - 1] : undefined;
    },
    clear: () => eventsSpy.mockClear(),
};
export default dealerBITestkit;
// Also export named for flexibility
export { dealerBITestkit };
//# sourceMappingURL=DealerBIMock.js.map