import { JwtAuthGuard } from '@/auth/guards/jwt-auth/jwt-auth.guard';
import { NotificationService } from './notification.service';
import {
  Controller,
  Delete,
  Get,
  Post,
  Body,
  Param,
  Patch,
  Query,
  Req,
  UseGuards,
} from '@nestjs/common';
import { GroupOwnerOrAdminGuard } from '@/auth/guards/group-owner.guard';
import { CreateNotificationDto } from './dto/create-notification.dto';

@Controller('notifications')
@UseGuards(JwtAuthGuard)
export class NotificationController {
  constructor(private readonly service: NotificationService) {}

  @Get()
  getAll(@Req() req, @Query() query) {
    return this.service.findAll(req.user.id, query);
  }

  @Patch(':id/read')
  markRead(@Param('id') id: string, @Req() req) {
    return this.service.markAsRead(id, req.user.id);
  }

  @Patch('read-all')
  markAll(@Req() req) {
    return this.service.markAllAsRead(req.user.id);
  }

  @Get('unread-count')
  count(@Req() req) {
    return this.service.countUnread(req.user.id);
  }

  @Delete(':id')
  delete(@Param('id') id: string, @Req() req) {
    return this.service.delete(id, req.user.id);
  }

  @Post('add')
  @UseGuards(GroupOwnerOrAdminGuard)
  add(@Req() req, @Body() dto: CreateNotificationDto) {
    return this.service.add(req.user.id, dto);
  }
}
