import { createAsyncThunk } from '@reduxjs/toolkit'; import { getStaffNotificationsApi, markNotificationReadApi, clearNotificationsApi } from '@api'; import { NotificationItem } from '@interfaces'; export const getStaffNotifications = createAsyncThunk< NotificationItem[], string >('notification/getStaffNotifications', async (staffId, { rejectWithValue }) => { try { return await getStaffNotificationsApi(staffId); } catch (error: any) { const serverMessage = error?.response?.data?.message || error.message || 'Failed to load notifications'; return rejectWithValue(serverMessage); } }); export const markNotificationRead = createAsyncThunk< { id: string }, { staffId: string; notificationId: string } >('notification/markNotificationRead', async (payload, { rejectWithValue }) => { try { await markNotificationReadApi(payload.staffId, payload.notificationId); return { id: payload.notificationId }; } catch (error: any) { const serverMessage = error?.response?.data?.message || error.message || 'Failed to mark notification as read'; return rejectWithValue(serverMessage); } }); export const clearNotifications = createAsyncThunk< void, string >('notification/clearNotifications', async (staffId, { rejectWithValue }) => { try { await clearNotificationsApi(staffId); } catch (error: any) { const serverMessage = error?.response?.data?.message || error.message || 'Failed to clear notifications'; return rejectWithValue(serverMessage); } });