import fetchMock from 'fetch-mock/cjs/client';
import { fieldValuesEmptyResponse, fieldValuesErrorResponse, fieldValuesResponseForAssignees, fieldValuesResponseForProjects, fieldValuesResponseForProjectsMoreData, fieldValuesResponseForStatuses, fieldValuesResponseForTypes, hydrateJqlStandardResponseForVRTesting, successfuluserHydrationResponse, successfulUserQueryResponse } from './mocks';
export const mockBasicFilterAGGFetchRequests = (opts = {
  withJiraFilterHydration: true
}) => {
  fetchMock.post(new RegExp(`/graphql`), async (_url, details) => {
    return new Promise(resolve => {
      var _mockBasicFilterData$;
      const requestBody = JSON.parse(details.body);

      // CLOL basic filter - edited/created by
      if (requestBody.operationName === 'userQuery') {
        return resolve(successfulUserQueryResponse);
      }
      if (requestBody.operationName === 'userHydration') {
        return resolve(successfuluserHydrationResponse);
      }

      // JLOL basic filter hydration for VR testing
      if (requestBody.operationName === 'hydrate' && opts.withJiraFilterHydration) {
        return resolve(hydrateJqlStandardResponseForVRTesting);
      }
      const filterType = requestBody.variables.jqlTerm;
      const searchString = requestBody.variables.searchString;
      const pageCursor = requestBody.variables.after;
      const mockBasicFilterData = {
        project: fieldValuesResponseForProjects,
        assignee: fieldValuesResponseForAssignees,
        type: fieldValuesResponseForTypes,
        status: fieldValuesResponseForStatuses
      };
      const resolveData = {
        data: ((_mockBasicFilterData$ = mockBasicFilterData[filterType]) === null || _mockBasicFilterData$ === void 0 ? void 0 : _mockBasicFilterData$.data) || []
      };

      // playwright test specifically requesting more projects data
      if (pageCursor) {
        resolve(fieldValuesResponseForProjectsMoreData);
      }

      // slowing down specifically for vr testing
      if (searchString === 'loading-message') {
        setTimeout(() => {
          resolve(resolveData);
        }, 5000);
      } // returning empty response for vr testing
      else if (searchString === 'empty-message') {
        resolve(fieldValuesEmptyResponse);
      } // returning error response for vr testing
      else if (searchString === 'error-message') {
        resolve(fieldValuesErrorResponse);
      } else {
        resolve(resolveData);
      }
    });
  });
};