import { FETCH_CARD, FETCH_NEXT_CARD } from '../constants/card';
import { getPeriorityNum } from '../utils/priority';

export function fetchNextCard(chapterId, cardType, priority, minRate) {
  return {
    type: FETCH_NEXT_CARD,
    api: true,
    auth: true,
    payload: {
      method: 'GET',
      url: '/cards/next',
      params: {
        chapter: chapterId,
        type: cardType,
        ...(priority ? { priority: getPeriorityNum(priority) } : {}),
        ...(minRate >= 0 ? { minRate } : {})
      }
    }
  };
}

export function fetchCard(cardId) {
  return {
    type: FETCH_CARD,
    api: true,
    auth: true,
    payload: {
      method: 'GET',
      url: `/cards/${cardId}`
    }
  };
}
