import client from '@/api/client';

const API_BASE = '/communication';

export interface Notification {
    id: string;
    userId: string;
    title: string;
    message: string;
    type: string;
    link: string | null;
    isRead: boolean;
    createdAt: string;
}

export const notificationService = {
    getNotifications: async (page?: number, limit?: number) => {
        let url = `${API_BASE}/notifications`;
        if (page && limit) {
            url += `?page=${page}&limit=${limit}`;
        }
        const response = await client.get(url);
        return response.data;
    },

    markAsRead: async (id: string) => {
        const response = await client.patch(`${API_BASE}/notifications/${id}/read`);
        return response.data;
    },

    markAllAsRead: async () => {
        const response = await client.patch(`${API_BASE}/notifications/read-all`);
        return response.data;
    },

    updatePushSubscription: async (subscription: any) => {
        const response = await client.post(`${API_BASE}/notifications/subscribe`, { subscription });
        return response.data;
    }
};

export default notificationService;
