import { Controller, Get, Param, Patch, Post, Body, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { NotificationsService } from './notifications.service';
import { JwtGuard } from '../../common/jwt.guard';
import { IamGuard, IamRoles } from '../../common/iam-adapter';
import { TestNotificationDto } from './notifications.dto';

@ApiTags('Notifications')
@Controller('notifications')
@UseGuards(JwtGuard)
@ApiBearerAuth('JWT-auth')
export class NotificationsController {
  constructor(private service: NotificationsService) {}

  @Get(':passengerId')
  @ApiOperation({ summary: 'Get notifications for passenger' })
  getForPassenger(@Param('passengerId') id: string) {
    return this.service.getForPassenger(id);
  }

  @Patch(':id/read')
  @ApiOperation({ summary: 'Mark notification as read' })
  markRead(@Param('id') id: string) {
    return this.service.markRead(id);
  }

  @Patch(':passengerId/read-all')
  @ApiOperation({ summary: 'Mark all notifications as read' })
  markAllRead(@Param('passengerId') id: string) {
    return this.service.markAllRead(id);
  }

  @Post('test')
  @UseGuards(IamGuard)
  @IamRoles('ADMIN', 'STAFF')
  @ApiOperation({ summary: 'Test notification delivery (Admin only)' })
  async testNotification(@Body() dto: TestNotificationDto) {
    return this.service.send(
      dto.templateKey,
      dto.recipient,
      dto.context,
      dto.channels as any,
    );
  }
}
