import { Controller, Get, Post, Body, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard, RolesGuard, Roles, UserRole } from '@genex/common';
import { AdminNotificationService } from '../../../application/services/admin-notification.service';
import { BroadcastDto } from '../dto/broadcast.dto';

@ApiTags('Admin - Notifications')
@Controller('admin/notifications')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN)
@ApiBearerAuth()
export class AdminNotificationController {
  constructor(private readonly adminNotificationService: AdminNotificationService) {}

  @Get('stats')
  @ApiOperation({ summary: 'Notification delivery stats (sent, failed, delivery rate, channel breakdown)' })
  async getStats() {
    return { code: 0, data: await this.adminNotificationService.getStats() };
  }

  @Post('broadcast')
  @ApiOperation({ summary: 'Send broadcast notification to all or segmented users' })
  async sendBroadcast(@Body() body: BroadcastDto) {
    return { code: 0, data: await this.adminNotificationService.sendBroadcast(body) };
  }

  @Get('templates')
  @ApiOperation({ summary: 'List available notification templates' })
  async getTemplates() {
    return { code: 0, data: await this.adminNotificationService.getTemplates() };
  }
}
