export interface NotifPreference {
  id: string;
  category: string;
  event: string;
  description: string;
  inApp: boolean;
  email: boolean;
  sms: boolean;
}

export async function getNotificationPreferences(): Promise<NotifPreference[] | null> {
  const res = await fetch('/api/notification-preferences');
  if (!res.ok) throw new Error('Failed to fetch notification preferences');
  const data = await res.json();
  return data.preferences;
}

export async function saveNotificationPreferences(
  preferences: NotifPreference[]
): Promise<NotifPreference[]> {
  const res = await fetch('/api/notification-preferences', {
    method: 'PUT',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ preferences }),
  });
  if (!res.ok) throw new Error('Failed to save notification preferences');
  const data = await res.json();
  return data.preferences;
}
