import { Injectable } from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';

@Injectable()
export class NotificationsService {
  constructor(private prisma: PrismaService) {}

  async findAll(tenantId: string) {
    return this.prisma.notification.findMany({
      where: { tenantId },
      orderBy: { createdAt: 'desc' },
      take: 50,
    });
  }

  async markRead(tenantId: string, id: string) {
    return this.prisma.notification.update({ where: { id }, data: { isRead: true } });
  }

  async markAllRead(tenantId: string) {
    return this.prisma.notification.updateMany({ where: { tenantId, isRead: false }, data: { isRead: true } });
  }

  async countUnread(tenantId: string) {
    return this.prisma.notification.count({ where: { tenantId, isRead: false } });
  }
}
