import generic from 'store/generic';
import cms from 'store/cms';
import account from 'store/account';
import genericApollo from 'store/genericApollo';
import list from 'store/list';
import error from 'store/error';

import settings from 'store/settings';
import { persistReducer } from 'redux-persist';

import storage from 'redux-persist/lib/storage'; // defaults to localStorage for web

const accountPersistConfig = {
  key: 'account',
  storage,
  whitelist: ['selectedResource'],
};

const reducers = {
  account: persistReducer(accountPersistConfig, account.reducer),
  generic: generic.reducer,
  genericApollo: genericApollo.reducer,
  list: list.reducer,
  cms: cms.reducer,
  settings: settings.reducer,
  error: error.reducer,
};

export interface AppStoreState {
  account: ReturnType<typeof account.reducer>;
  generic: ReturnType<typeof generic.reducer>;
  genericApollo: ReturnType<typeof genericApollo.reducer>;
  cms: ReturnType<typeof cms.reducer>;
  list: ReturnType<typeof list.reducer>;
  settings: ReturnType<typeof settings.reducer>;
  error: ReturnType<typeof error.reducer>;
}

export default reducers;
