/**
 * @flow
 *
 * This file configures the Redux store
 *
 * To keep things simple, and because Firebase already acts as a state management solution,
 * we are only using Redux for the following:
 *
 * 1) `redux-form` integration
 * 2) Basic UI state, i.e. the loading modal
 */
import { createStore, combineReducers, applyMiddleware } from "redux";
import ReduxThunk from "redux-thunk";

import retryImagesReducer from "./reducers/retryImagesReducer";
import retryCountReducer from "./reducers/retryCountReducer";
import uploadedImageReducer from "./reducers/uploadedImageReducer";
import activityDataReducer from "./reducers/activityDataReducer";
import isLastReducer from "./reducers/isLastReducer";
import sensorDataReducer from "./reducers/sensorDataReducer";
import vechicleDetailsReducer from "./reducers/vechicleDetailsReducer";
import imageClickedCountReducer from "./reducers/imageClickedCountReducer";
import rcbPreviewDataReducer from "./reducers/rcbPreviewDataReducer";
import popInstructionsReducer from "./reducers/popInstructionsReducer";
import failedDataReducer from "./reducers/failedDataReducer";
import globalModalReducer from "./reducers/globalModalReducer";
import uploadingDataReducer from "./reducers/uploadingDataReducer";
import networkReducer from "./reducers/networkReducer";
import commonFlagsReducer from "./reducers/commonFlagsReducer";
import uploadProgressReducer from "./reducers/uploadProgressReducer";

const appReducer = combineReducers({
  UploadImageData: uploadedImageReducer,
  RetryImageData: retryImagesReducer,
  RetryCountData: retryCountReducer,
  activityData: activityDataReducer,
  isLastData: isLastReducer,
  sensorImageData: sensorDataReducer,
  vechicleDetails: vechicleDetailsReducer,
  imageClickedCountDetails: imageClickedCountReducer,
  rcbPreviewData: rcbPreviewDataReducer,
  popInstructionsData: popInstructionsReducer,
  failedData: failedDataReducer,
  globalModal: globalModalReducer,
  uploadingData: uploadingDataReducer,
  network: networkReducer,
  commonFlags: commonFlagsReducer,
  uploadProgress: uploadProgressReducer,
});

const rootReducer = (state, action) => appReducer(state, action);

const store = createStore(rootReducer, applyMiddleware(ReduxThunk));
export default store;
