import { createCoreAPIClient } from "@/lib/features/coreClient";

export interface TargetNotificationPayload {
  member_emails: string[];
  title: string;
  body: string;
  image: string;
  name: string;
  additional_data: Record<string, string>;
  persist: boolean;
}

const coreClient = createCoreAPIClient();

export async function sendTargetNotification(
  payload: TargetNotificationPayload,
) {
  try {
    const response = await coreClient<{ success: boolean; message?: string }>(
      "/v1/admin-console/notifications/campaigns",
      {
        method: "POST",
        body: JSON.stringify(payload),
      },
    );
    return response;
  } catch (error) {
    return {
      success: false,
      message: (error as Error)?.message ?? "Failed to send notification",
      data: null,
    };
  }
}
