import { Controller, Get, Put, Param, Query, UseGuards, Req } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { NotificationService } from '../../../application/services/notification.service';
import { NotificationQueryDto } from '../dto/notification-query.dto';
import { MarkReadParamDto } from '../dto/mark-read.dto';

@ApiTags('Notifications')
@Controller('notifications')
@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
export class NotificationController {
  constructor(private readonly notificationService: NotificationService) {}

  @Get()
  @ApiOperation({ summary: 'Get user notifications' })
  async list(@Req() req: any, @Query() query: NotificationQueryDto) {
    return { code: 0, data: await this.notificationService.getByUserId(req.user.id, query.page, query.limit) };
  }

  @Get('unread-count')
  @ApiOperation({ summary: 'Get unread count' })
  async unreadCount(@Req() req: any) {
    return { code: 0, data: { count: await this.notificationService.countUnread(req.user.id) } };
  }

  @Put(':id/read')
  @ApiOperation({ summary: 'Mark notification as read' })
  async markAsRead(@Param() params: MarkReadParamDto, @Req() req: any) {
    await this.notificationService.markAsRead(params.id, req.user.id);
    return { code: 0, data: null };
  }
}
