import { transformRestResponse } from '../../../utilities/articles'
import { SET_ARTICLE_BROWSER_TYPE, START_ARTICLES, STOP_ARTICLES, UPDATE_ARTICLE, UPDATE_ARTICLES } from '../../types'

export const setArticleBrowserType = ({ categorySlug, type }) => ({
  browserType: type,
  categorySlug,
  type: SET_ARTICLE_BROWSER_TYPE
})

export const startArticles = () => ({
  hasMore: true,
  type: START_ARTICLES
})

export const stopArticles = () => ({
  hasMore: false,
  type: STOP_ARTICLES
})

// @todo - do not do this `transformRestResponse` here
export const updateArticles = ({ append = true, category = null, hasMore, items }) => ({
  append,
  articles: hasMore !== undefined ? transformRestResponse(items) : [],
  category,
  hasMore: items.length !== 0,
  type: UPDATE_ARTICLES
})

// @todo - do not do this `transformRestResponse` here
export const updateArticle = ({ hasMore = false, items }) => ({
  article: transformRestResponse(items),
  hasMore,
  type: UPDATE_ARTICLE
})
