import axios from 'axios';
import {
  getDatasetByDOI,
  getDatasetsByInvestigationId,
} from '../api/icat/icatPlus';
import {
  FETCH_DATASETS_BY_DOI,
  FETCH_DATASETS_BY_INVESTIGATION,
} from '../constants/actionTypes';

export function fetchDatasetsByDOI(sessionId, doi) {
  return function (dispatch) {
    dispatch({
      type: FETCH_DATASETS_BY_DOI,
      payload: axios.get(getDatasetByDOI(sessionId, doi)),
    });
  };
}

export function fetchDatasetsByInvestigationId(sessionId, investigationId) {
  return function (dispatch) {
    dispatch({
      type: FETCH_DATASETS_BY_INVESTIGATION,
      payload: axios.get(
        getDatasetsByInvestigationId(sessionId, investigationId)
      ),
    });
  };
}
