import { Controller, Get, Param, ParseUUIDPipe, Patch, Post, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard';
import { successResponse } from '../../common/responses/api-response';
import { NotificationService } from './notification.service';

/**
 * Notifications are a per-user feed — NOT gated by PermissionGuard
 * (just by JWT auth). Every authed user has their own notification
 * bell regardless of module permissions.
 */
@Controller('notifications')
@UseGuards(JwtAuthGuard)
export class NotificationController {
  constructor(private readonly service: NotificationService) {}

  @Get()
  async list() {
    const data = await this.service.listForCurrentUser();
    return successResponse(data, 'Notifications fetched');
  }

  @Get('unread-count')
  async unreadCount() {
    const count = await this.service.unreadCount();
    return successResponse({ count }, 'Unread count');
  }

  @Patch(':id/read')
  async markRead(@Param('id', ParseUUIDPipe) id: string) {
    await this.service.markRead(id);
    return successResponse({ id }, 'Marked as read');
  }

  @Post('mark-all-read')
  async markAllRead() {
    await this.service.markAllRead();
    return successResponse({}, 'All marked as read');
  }
}
