import { getDataAction, setTableAction } from '../slices';
import createEpicGetData from '@/modules/@common/Table/redux/epics';

import { GET_DATA } from '@/graphql/services/permissions/constatnts';

const gqlQuery = `
  query ${GET_DATA} {
    ${GET_DATA} {
      roles
      permissions {
        name
        roles
      }
    }
  }
`;

export default createEpicGetData({
  gqlQuery,
  triggerActionType: getDataAction.type,
  processBodyRequest: () => {
    const variables = {};

    return {
      payload: variables,
    };
  },
  processResponse: ({ data }) => {
    const res = data[GET_DATA];

    return {
      records: res,
      recordsTotal: res.permissions.length,
      allRecordsCount: res.permissions.length,
    };
  },
  setTableAction,
});
