import api from '../api.service'

/**
 * Get workspace
 * @return {Promise<*|undefined>}
 */
export const getWorkspace = () => {
  return api.storageAPI('generic-objects/data-files/b91356d7-e1fb-423a-b7ee-5eb732f56297')
}

/**
 * Save workspace to data store as json file
 * @param workspace
 * @return {Promise<*|undefined>}
 */
export const saveWorkspace = workspace => {
  const data = new FormData()

  const blob = new Blob([JSON.stringify(workspace)], {
    type: 'application/json'
  })
  data.append('file', blob)

  return api.storageAPI({
    url: 'generic-objects/data-files/b91356d7-e1fb-423a-b7ee-5eb732f56297',
    method: 'PUT',
    data
  })
}

export const runFilter = data => {
  return api.storageAPI({
    url: '/generic-objects/filter',
    method: 'POST',
    data
  })
}
