const parseResponseBody = async (response) => {
  try {
    return await response.json();
  } catch (error) {
    return null;
  }
};

export const getActiveSocialMediaPlatforms = async () => {
  const response = await fetch('/api/social-media/platforms');
  const payload = await parseResponseBody(response);

  if (!response.ok) {
    const error = new Error(payload?.error || payload?.message || 'Plattformen konnten nicht geladen werden');
    error.status = response.status;
    error.payload = payload;
    throw error;
  }

  return payload || [];
};
