type BarkPayload = {
  title: string;
  body: string;
  group?: string;
  url?: string;
  sound?: string;
  icon?: string;
};

export const sendBarkPush = async (baseUrl: string, payload: BarkPayload) => {
  const response = await fetch(baseUrl, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(payload),
  });
  const data = await response.json().catch(() => ({}));
  if (!response.ok) {
    const error = new Error(`Bark error: ${response.status}`);
    (error as Error & { response?: unknown }).response = data;
    throw error;
  }
  return data;
};
