export function getCustomerSpaceEnvironment(id) {
  return fetch(`${eXo.env.portal.context}/${eXo.env.portal.rest}/customer-space/space/environment/${id}`, {
    method: 'GET',
    credentials: 'include',
  }).then((resp) => {
    if (resp && resp.ok) {
      return resp.json();
    } else {
      throw new Error('Error getting saved customer space environment');
    }
  });
}

export function getCustomerSpaceUserSettings() {
  return fetch(`${eXo.env.portal.context}/${eXo.env.portal.rest}/customer-space/space/settings`, {
    method: 'GET',
    credentials: 'include',
  }).then((resp) => {
    if (resp && resp.ok) {
      return resp.json();
    } else {
      throw new Error('Error getting saved customer space environment');
    }
  });
}

export function getCustomerSpaceInfo(spaceGroupId) {
  return fetch(`${eXo.env.portal.context}/${eXo.env.portal.rest}/customer-space/space/${spaceGroupId}`, {
    method: 'GET',
    credentials: 'include',
  }).then((resp) => {
    if (resp && resp.ok) {
      return resp.json();
    } else {
      throw new Error('Error getting customer space info');
    }
  });
}

export function getCustomerSpaceEnvironments(groupId) {
  return fetch(`${eXo.env.portal.context}/${eXo.env.portal.rest}/customer-space/space/environments?groupId=${groupId}`, {
    method: 'GET',
    credentials: 'include',
  }).then((resp) => {
    if (resp && resp.ok) {
      return resp.json();
    } else {
      throw new Error('Error getting saved customer space environment');
    }
  });
}