import { Body, Controller, Get, Param, Patch, Post, Query } from '@nestjs/common';
import { CreateNotificationDto } from './dto/create-notification.dto';
import { MarkNotificationReadDto } from './dto/mark-notification-read.dto';
import { NotificationService } from './notification.service';

@Controller('notifications')
export class NotificationController {
  constructor(private readonly notificationService: NotificationService) {}

  @Get()
  list(
    @Query('recipientId') recipientId: string,
    @Query('unreadOnly') unreadOnly?: string,
    @Query('limit') limit?: string,
  ) {
    return this.notificationService.list({
      recipientId,
      unreadOnly: unreadOnly === 'true',
      limit: limit ? Number(limit) : undefined,
    });
  }

  @Post()
  create(@Body() dto: CreateNotificationDto) {
    return this.notificationService.create(dto);
  }

  @Patch(':id/read')
  markRead(@Param('id') id: string, @Body() dto: MarkNotificationReadDto) {
    return this.notificationService.markRead(id, dto.recipientId);
  }

  @Patch('read-all')
  markAllRead(@Body() dto: MarkNotificationReadDto) {
    return this.notificationService.markAllRead(dto.recipientId);
  }
}
