import {
  Controller, Get, Put, Delete,
  Param, UseGuards, Req
} from '@nestjs/common';
import { NotificationsService } from './notifications.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';

@Controller('notifications')
@UseGuards(JwtAuthGuard)
export class NotificationsController {
  constructor(private readonly notificationsService: NotificationsService) {}

  // Lister mes notifications
  @Get()
  findAll(@Req() req) {
    return this.notificationsService.findAll(req.user.id);
  }

  // Compter les non lues
  @Get('unread/count')
  countUnread(@Req() req) {
    return this.notificationsService.countUnread(req.user.id);
  }

  // Marquer une comme lue
  @Put(':id/read')
  markAsRead(@Req() req, @Param('id') id: string) {
    return this.notificationsService.markAsRead(+id, req.user.id);
  }

  // Marquer toutes comme lues
  @Put('read/all')
  markAllAsRead(@Req() req) {
    return this.notificationsService.markAllAsRead(req.user.id);
  }

  // Supprimer une notification
  @Delete(':id')
  remove(@Req() req, @Param('id') id: string) {
    return this.notificationsService.remove(+id, req.user.id);
  }

  // Supprimer toutes les lues
  @Delete('read/all')
  removeAllRead(@Req() req) {
    return this.notificationsService.removeAllRead(req.user.id);
  }
}