import { fetchJson } from '../../auth/api-client'; import type { SchedulingResponse, NotifyRequest, NotifyBatchRequest, NotifyBatchResult, NotificationRecord, NotificationStatus, UpdateNotificationRequest, } from './types'; const BASE = '/api/scheduling'; export async function fetchSuggestions(targetId?: number): Promise { const params = new URLSearchParams(); if (targetId !== undefined) params.set('targetId', String(targetId)); const qs = params.toString(); return fetchJson(`${BASE}/suggestions${qs ? `?${qs}` : ''}`); } export async function sendNotify( body: NotifyRequest, ): Promise<{ success: boolean; message: string; record?: NotificationRecord }> { return fetchJson(`${BASE}/notify`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }); } export async function sendNotifyBatch( body: NotifyBatchRequest, ): Promise<{ success: boolean; message: string; result: NotifyBatchResult }> { return fetchJson(`${BASE}/notify/batch`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }); } export async function fetchNotifications( status?: NotificationStatus, limit?: number, ): Promise<{ records: NotificationRecord[] }> { const params = new URLSearchParams(); if (status) params.set('status', status); if (limit) params.set('limit', String(limit)); const qs = params.toString(); return fetchJson(`${BASE}/notify${qs ? `?${qs}` : ''}`); } export async function updateNotification( id: number, body: UpdateNotificationRequest, ): Promise<{ success: boolean; record?: NotificationRecord; message?: string }> { return fetchJson(`${BASE}/notify/${id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }); }