import api from "@/lib/axios";
import { API_ENDPOINTS } from "@/lib/endpoints";

import {
  NotificationActionResponse,
  NotificationListResponse,
  NotificationQuery,
  UnreadCountResponse,
} from "../notification.types";

class NotificationService {
  getNotifications(params: NotificationQuery = {}) {
    const unreadOnly = params.unread_only ?? false;
    return api.get<NotificationListResponse>(
      `${API_ENDPOINTS.NOTIFICATION.NOTIFICATION_LIST(params)}&unread_only=${unreadOnly}`,
    );
  }

  getUnreadCount() {
    return api.get<UnreadCountResponse>(
      API_ENDPOINTS.NOTIFICATION.NOTIFICATION_UNREAD_COUNT,
    );
  }

  markAsRead(id: string) {
    return api.patch<NotificationActionResponse>(
      API_ENDPOINTS.NOTIFICATION.NOTIFICATION_READ(id),
    );
  }

  markAllAsRead() {
    return api.post<NotificationActionResponse>(
      API_ENDPOINTS.NOTIFICATION.NOTIFICATION_READ_ALL,
    );
  }
}

const notificationService = new NotificationService();

export default notificationService;
