import type { FastifyRequest, FastifyReply } from 'fastify';
import * as notificationService from '../services/notification.service.js';

export async function listHandler(request: FastifyRequest, _reply: FastifyReply) {
  const { page, limit } = request.query as { page?: number; limit?: number };
  return notificationService.list(request.user.id, page, limit);
}

export async function unreadCountHandler(request: FastifyRequest, _reply: FastifyReply) {
  const count = await notificationService.unreadCount(request.user.id);
  return { count };
}

export async function markReadHandler(request: FastifyRequest, _reply: FastifyReply) {
  const { id } = request.params as { id: string };
  await notificationService.markRead(id);
  return { ok: true };
}

export async function markAllReadHandler(request: FastifyRequest, _reply: FastifyReply) {
  await notificationService.markAllRead(request.user.id);
  return { ok: true };
}

export async function dismissHandler(request: FastifyRequest, _reply: FastifyReply) {
  const { id } = request.params as { id: string };
  await notificationService.dismiss(id, request.user.id);
  return { ok: true };
}

export async function dismissAllHandler(request: FastifyRequest, _reply: FastifyReply) {
  await notificationService.dismissAll(request.user.id);
  return { ok: true };
}
