import { sendPushNotificationToUsers } from './push.service.js';
import { logger } from '../utils/logger.js';

export const notifyNewTodoAssignment = async (assignedUserIds, title, todoId, excludeUserId) => {
  if (!assignedUserIds || !Array.isArray(assignedUserIds) || assignedUserIds.length === 0) {
    return;
  }

  try {
    await sendPushNotificationToUsers(
      assignedUserIds,
      {
        title: 'Nová úloha',
        body: `Bola vám priradená úloha: ${title}`,
        icon: '/icon-192.png',
        badge: '/badge-72.png',
        data: { url: '/todos', todoId },
      },
      excludeUserId,
    );
  } catch (error) {
    logger.error('Failed to send push notifications for new todo', error);
  }
};

export const notifyUpdatedTodoAssignment = async (newlyAssignedUserIds, title, todoId, excludeUserId) => {
  if (!newlyAssignedUserIds || newlyAssignedUserIds.length === 0) {
    return;
  }

  try {
    await sendPushNotificationToUsers(
      newlyAssignedUserIds,
      {
        title: 'Priradená úloha',
        body: `Bola vám priradená úloha: ${title}`,
        icon: '/icon-192.png',
        badge: '/badge-72.png',
        data: { url: '/todos', todoId },
      },
      excludeUserId,
    );
  } catch (error) {
    logger.error('Failed to send push notifications for updated todo', error);
  }
};
