import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
import { Roles } from '../common/decorators/roles.decorator';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { CreateNotificationDto } from './dto/create-notification.dto';
import { NotificationsService } from './notifications.service';

@Controller('notifications')
@UseGuards(JwtAuthGuard, RolesGuard)
export class NotificationsController {
  constructor(private readonly notificationsService: NotificationsService) {}

  @Get()
  @Roles('CUSTOMER', 'DRIVER', 'RESTAURANT', 'ADMIN', 'SUPER_ADMIN')
  index(@Req() req: { user: { sub: string; role: string } }) {
    return this.notificationsService.list(req.user as never);
  }

  @Get('providers')
  @Roles('ADMIN', 'SUPER_ADMIN')
  providers() {
    return this.notificationsService.getPushProviders();
  }

  @Post('test')
  @Roles('ADMIN', 'SUPER_ADMIN')
  test(@Req() req: { user: { sub: string; role: string } }, @Body() body: CreateNotificationDto) {
    return this.notificationsService.createAdminNotification(req.user as never, body);
  }
}
