import {HttpRequest, RestConstant, StatusCode} from 'constants';

const initialState = {
  data: undefined,
  error: undefined,
};

export const getCategories = async payload => {
  const newState = {...initialState};
  const url = `${RestConstant.productCategories}?page_id=${payload.page_id}&page_size=${payload.page_size}`;
  try {
    const response = await HttpRequest.get(url);
    console.log(response);
    switch (response.request.status) {
      case StatusCode.OK:
        newState.data = response.data;
        return newState;
      case StatusCode.UNAUTHORIZED:
        newState.error = response.response.data;
        return newState;
      case StatusCode.SERVER_ERROR:
        newState.error = response.response.data;
        return newState;
    }
  } catch (error) {
    console.log(error);
    console.log(error);
  }
};
