import api from 'src/config/api';

export const createQRCode = userCode =>
  api.post<any>(
    '/external-endpoints/19',
    {},
    {
      params: {
        code: userCode,
      },
    },
  );

export const getEvents = () => api.get<any>('/external-endpoints/1');

export const getEventData = eventId =>
  api.get<any>('/external-endpoints/1', {
    params: {
      EventId: eventId,
    },
  });

export const getEventsBySite = site =>
  api.get<any>('/external-endpoints/2', {
    params: {
      site: site,
    },
  });

export const getExtraFields = eventId =>
  api.get<any>('/external-endpoints/3', {
    params: {
      EventId: eventId,
    },
  });

export const getUserData = userId =>
  api.get<any>('/external-endpoints/6', {
    params: {
      employeeId: userId,
    },
  });

export const getFieldsCatalogues = fieldName =>
  api.get<any>('/external-endpoints/21', {
    params: {
      Catalogues: fieldName,
    },
  });

export const submitRegistration = (
  formId,
  employeeId,
  userData,
  guestsNumber,
  extraFieldsData,
  familyAssistantData,
  teamMembersData,
  volunteersData,
) =>
  api.post<any>(
    '/external-endpoints/4',
    {},
    {
      params: {
        EventId: formId,
        EmployeeNumber: employeeId,
        EmployeeName: `${userData.FirstName} ${userData.LastName}`,
        PhoneNumber:
          userData.PhoneNumber === '' ? '528113239659' : userData.PhoneNumber,
        Unionized: userData.EmployeeCategoryCode === 'EMPCAT01' ? 1 : 0,
        Guests: guestsNumber,
        Source: '89dd9a8a-01f5-4e5b-b8a8-1fe8b2926565',
        Family: familyAssistantData,
        ExtraFields: extraFieldsData,
        Team: teamMembersData,
        Volunteers: volunteersData,
      },
    },
  );

export const subscribeIntoWaitingList = (
  formId,
  employeeId,
  userData,
  guestsNumber,
) =>
  api.post<any>(
    '/external-endpoints/5',
    {},
    {
      params: {
        EventId: formId,
        EmployeeNumber: employeeId,
        EmployeeName: `${userData.FirstName} ${userData.LastName}`,
        PhoneNumber:
          userData.PhoneNumber === '' ? '528113239659' : userData.PhoneNumber,
        Unionized: userData.EmployeeCategoryCode === 'EMPCAT01' ? 1 : 0,
        Guests: guestsNumber,
        Source: '89dd9a8a-01f5-4e5b-b8a8-1fe8b2926565',
        Family: '',
        ExtraFields: '',
        Team: '',
        Volunteers: '',
      },
    },
  );
