/**
 *  Create Redux Atom Factory
 */
export default ({
  actionTypesFactory = () => ({}),
  selectorsFactory = () => ({}),
  repositoryFactory = () => ({}),
  actionCreatorsFactory = () => ({}),
  initialStateFactory = () => ({}),
  reducerFactory = () => ({})
}) => ({
  namespace = '',
  rootUrl = '',
  rootSelector = state => state
}) => {
  const actionTypes = actionTypesFactory(namespace)
  const selectors = selectorsFactory(rootSelector)
  const repository = repositoryFactory(rootUrl)
  const actionCreators = actionCreatorsFactory(actionTypes, selectors, repository)
  const initialState = initialStateFactory()
  const reducer = reducerFactory(actionTypes, initialState)

  return {
    actionTypes,
    ...actionTypes,
    actionCreators,
    ...actionCreators,
    reducer,
    selectors,
    ...selectors
  }
}

const noop = () => ({})

/**
 *  Create Redux Atom Factory
 */
export default ({
  actionTypesFactory = noop,
  selectorsFactory = noop,
  repositoryFactory = noop,
  actionCreatorsFactory = noop,
  initialStateFactory = noop,
  reducerFactory = noop
}) => ({
  namespace = '',
  data = {},
  rootUrl = '',
  rootSelector = state => state
}) => {
  const actionTypes = actionTypesFactory(namespace)
  const selectors = selectorsFactory(rootSelector)
  const repository = repositoryFactory(rootUrl)
  const actionCreators = actionCreatorsFactory(actionTypes, selectors, repository)
  const initialState = initialStateFactory(data)
  const reducer = reducerFactory(actionTypes, initialState)

  return {
    actionTypes,
    ...actionTypes,
    actionCreators,
    ...actionCreators,
    reducer,
    selectors,
    ...selectors
  }
}

add initial data