/**
 * @ai-summary API calls for notifications feature
 */

import { apiClient } from '../../../core/api/client';
import {
  NotificationSummary,
  DueMaintenanceItem,
  ExpiringDocument,
  UserNotification,
  UnreadNotificationCount
} from '../types/notifications.types';

export const notificationsApi = {
  getSummary: async (): Promise<NotificationSummary> => {
    const response = await apiClient.get('/notifications/summary');
    return response.data;
  },

  getDueMaintenanceItems: async (): Promise<DueMaintenanceItem[]> => {
    const response = await apiClient.get('/notifications/maintenance');
    return response.data;
  },

  getExpiringDocuments: async (): Promise<ExpiringDocument[]> => {
    const response = await apiClient.get('/notifications/documents');
    return response.data;
  },

  // In-App Notifications
  getInAppNotifications: async (limit = 20, includeRead = false): Promise<UserNotification[]> => {
    const response = await apiClient.get('/notifications/in-app', {
      params: { limit, includeRead: includeRead.toString() }
    });
    return response.data;
  },

  getUnreadCount: async (): Promise<UnreadNotificationCount> => {
    const response = await apiClient.get('/notifications/in-app/count');
    return response.data;
  },

  markAsRead: async (id: string): Promise<UserNotification> => {
    const response = await apiClient.put(`/notifications/in-app/${id}/read`);
    return response.data;
  },

  markAllAsRead: async (): Promise<{ markedAsRead: number }> => {
    const response = await apiClient.put('/notifications/in-app/read-all');
    return response.data;
  },

  deleteNotification: async (id: string): Promise<void> => {
    await apiClient.delete(`/notifications/in-app/${id}`);
  },
};
