import {
  BadRequestException,
  Body,
  Controller,
  Delete,
  Get,
  Logger,
  NotFoundException,
  Param,
  Post,
  Put,
  Query,
  Req,
  UseGuards,
} from '@nestjs/common';
import { ApiBody, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
import { PesService } from './pes.service';
import { CreatePesCampaignDto, PesCampaignResponseDto, UpdatePesCampaignDto } from './dto/pes-campaign.dto';
import { SendVerificationDto, SMTPConnectionTestProp, VerifyEmailDto } from './abstracts/pes.abstract';
import { CreatePesTemplateDto, PesTemplateResponseDto, UpdatePesTemplateDto } from './dto/pes-template.dto';
import { CreatePesSendingProfileDto, PesSendingProfileResponseDto, UpdatePesSendingProfileDto } from './dto/pes-sending-profile.dto';
import { JwtAuthGuard } from 'common/guards/jwt-auth.guard';
import { CreatePesLandingPageDto, PesLandingPageResponseDto, UpdatePesLandingPageDto } from './dto/pes-landing-page.dto';
import { CreatePesRecipientGroupDto, PesRecipientGroupResponseDto } from './dto/pes-recipient-group.dto';

@ApiTags('pes')
@Controller({ path: 'pes', version: '1' })
export class PesController {
  private readonly logger = new Logger(PesController.name);
  constructor(private readonly pesService: PesService) {}

  // Campaign endpoints
  @Post('campaigns')
  @ApiBody({
    type: CreatePesCampaignDto,
    description: 'Create a new PES campaign',
  })
  @ApiResponse({
    status: 201,
    description: 'Campaign created successfully',
    type: PesCampaignResponseDto,
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  @ApiResponse({
    status: 500,
    description: 'Internal Server Error',
  })
  @UseGuards(JwtAuthGuard)
  async createCampaign(@Req() req: any, @Body() dto: CreatePesCampaignDto): Promise<PesCampaignResponseDto> {
    const { user } = req;
    if (!user) {
      this.logger.error('User not authenticated');
      throw new BadRequestException('User not authenticated');
    }
    this.logger.log(`Creating PES campaign with data: ${JSON.stringify(dto)}`);
    this.logger.debug(`User email: ${user.email}`);
    return await this.pesService.createCampaign(user.email, dto);
  }

  @Put('campaigns/:id')
  @ApiBody({
    type: UpdatePesCampaignDto,
    description: 'Update an existing PES campaign',
  })
  @ApiResponse({
    status: 200,
    description: 'Campaign updated successfully',
    type: PesCampaignResponseDto,
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  async updateCampaign(@Param('id') id: string, @Body() dto: UpdatePesCampaignDto): Promise<PesCampaignResponseDto> {
    return this.pesService.updateCampaign(id, dto);
  }

  @Delete('campaigns/:id')
  @ApiParam({
    name: 'id',
    description: 'ID of the campaign to delete',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'Campaign deleted successfully',
  })
  @ApiResponse({
    status: 404,
    description: 'Campaign not found',
  })
  @ApiResponse({
    status: 500,
    description: 'Internal Server Error',
  })
  async deleteCampaign(@Param('id') id: string) {
    return this.pesService.deleteCampaign(id);
  }

  @Post('template/test-email')
  @ApiParam({
    name: 'id',
    description: 'ID of the template to send',
    type: String,
  })
  @ApiBody({
    description: 'Send a test email using a PES template',
    schema: {
      type: 'object',
      properties: {
        email: { type: 'string', format: 'email', example: 'test@example.com' },
      },
    },
  })
  @ApiResponse({
    status: 200,
    description: 'Test email sent successfully',
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  async sendTestEmail(@Body() body: { id: string; email: string }): Promise<{ success: boolean; message: string }> {
    const { id, email } = body;
    this.logger.log(`Sending test email to ${email} using template ID ${id}`);
    return this.pesService.sendTestEmail(email, id);
  }

  @Post('campaigns/send')
  @ApiParam({
    name: 'id',
    description: 'ID of the campaign to send',
    type: String,
  })
  @ApiBody({
    description: 'Send a campaign email to a recipient',
    schema: {
      type: 'object',
      properties: {
        email: { type: 'string', format: 'email', example: 'test@example.com' },
        campaignId: { type: 'string', example: '12345' },
      },
    },
  })
  @ApiResponse({
    status: 200,
    description: 'Campaign email sent successfully',
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  async sendCampaignEmail(@Body() body: { email: string; campaignId: string }): Promise<{ success: boolean; message: string }> {
    this.logger.log(`Sending campaign email with data: ${JSON.stringify(body)}`);
    const { email, campaignId } = body;
    if (!email || !campaignId) {
      throw new BadRequestException('Email and Campaign ID are required to send the campaign');
    }
    this.logger.log(`Sending campaign email to ${email} with campaign ID ${campaignId}`);
    return this.pesService.sendCampaignEmail(email, campaignId);
  }

  // Email verification endpoints
  @Post('verification/send')
  @ApiBody({
    type: SendVerificationDto,
    description: 'Send verification email to the user',
  })
  @ApiResponse({
    status: 200,
    description: 'Verification email sent successfully',
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  @ApiResponse({
    status: 500,
    description: 'Internal Server Error',
  })
  @UseGuards(JwtAuthGuard)
  async sendVerification(@Req() req: any, @Body('email') dto: string) {
    const { user } = req;
    this.logger.log(`User ${JSON.stringify(user.email)} is sending verification email to ${dto}`);
    return this.pesService.sendVerificationEmail(dto, user.email);
  }

  @Post('verification/verify')
  @ApiBody({
    type: VerifyEmailDto,
    description: 'Verify the user email with OTP',
  })
  @ApiResponse({
    status: 200,
    description: 'Email verified successfully',
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  @UseGuards(JwtAuthGuard)
  async verifyEmail(@Req() req: any, @Body('email') email: string, @Body('otpCode') otp: string) {
    const { user } = req;
    if (!user) {
      throw new Error('User not authenticated');
    }
    return this.pesService.verifyEmail(email, otp, user.id);
  }

  @Post('verification/resend')
  @ApiBody({
    type: SendVerificationDto,
    description: 'Resend verification email to the user',
  })
  @ApiResponse({
    status: 200,
    description: 'Verification email resent successfully',
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  async resendVerification(@Body() dto: SendVerificationDto) {
    return this.pesService.resendVerificationEmail(dto);
  }

  @Get('verification/status')
  @ApiResponse({
    status: 200,
    description: 'Check email verification status',
    schema: {
      type: 'object',
      properties: {
        isVerified: {
          type: 'boolean',
          description: 'Indicates if the email is verified',
        },
      },
    },
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  checkStatus(@Query('email') email: string): Promise<{ isVerified: boolean }> {
    return this.pesService.checkEmailVerificationStatus(email);
  }

  // Verified User endpoints
  @Get('verified-user')
  @UseGuards(JwtAuthGuard)
  async getVerifiedUser(@Req() req: any): Promise<any> {
    const { user } = req;
    if (!user) {
      throw new Error('User not authenticated');
    }
    return this.pesService.getVerifiedUserByEmail(user.email);
  }

  // Template endpoints
  @Get('templates')
  @ApiResponse({
    status: 200,
    description: 'List of PES templates',
    type: [PesTemplateResponseDto],
  })
  @ApiResponse({
    status: 500,
    description: 'Internal Server Error',
  })
  async getTemplates(): Promise<PesTemplateResponseDto[]> {
    return this.pesService.getAllTemplates();
  }

  @Post('templates')
  @ApiBody({
    type: CreatePesTemplateDto,
    description: 'Create a new PES template',
  })
  @ApiResponse({
    status: 201,
    description: 'Template created successfully',
    type: PesTemplateResponseDto,
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  @ApiResponse({
    status: 500,
    description: 'Internal Server Error',
  })
  async createTemplate(@Body() dto: CreatePesTemplateDto): Promise<PesTemplateResponseDto> {
    return this.pesService.createTemplate(dto);
  }

  @Get('templates/:templateId')
  @ApiParam({
    name: 'templateId',
    description: 'ID of the template to retrieve',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'Template retrieved successfully',
    type: PesTemplateResponseDto,
  })
  @ApiResponse({
    status: 404,
    description: 'Template not found',
  })
  async getTemplateById(@Param('templateId') templateId: string): Promise<PesTemplateResponseDto> {
    const template = await this.pesService.getTemplateById(templateId);
    if (!template) {
      throw new NotFoundException(`Template with ID ${templateId} not found`);
    }
    return template;
  }

  @Get('templates/verified-user/:verifiedUserId')
  @ApiParam({
    name: 'verifiedUserId',
    description: 'ID of the verified user to get templates for',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'List of templates for the verified user',
    type: [PesTemplateResponseDto],
  })
  async getTemplatesByVerifiedUserId(@Param('verifiedUserId') verifiedUserId: string): Promise<PesTemplateResponseDto[]> {
    this.logger.log(`Fetching templates for verified user with ID: ${verifiedUserId}`);
    return this.pesService.getTemplatesByVerifiedUserId(verifiedUserId);
  }

  @Put('templates/:templateId')
  @ApiParam({
    name: 'templateId',
    description: 'ID of the template to update',
    type: String,
  })
  @ApiBody({
    type: CreatePesTemplateDto,
    description: 'Update an existing PES template',
  })
  @ApiResponse({
    status: 200,
    description: 'Template updated successfully',
    type: PesTemplateResponseDto,
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  @ApiResponse({
    status: 404,
    description: 'Template not found',
  })
  async updateTemplate(@Param('templateId') templateId: string, @Body() dto: UpdatePesTemplateDto): Promise<PesTemplateResponseDto> {
    const updatedTemplate = await this.pesService.updateTemplate(templateId, dto);
    if (!updatedTemplate) {
      throw new NotFoundException(`Template with ID ${templateId} not found`);
    }
    return updatedTemplate;
  }

  @Delete('templates/:templateId')
  @ApiParam({
    name: 'templateId',
    description: 'ID of the template to delete',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'Template deleted successfully',
  })
  @ApiResponse({
    status: 404,
    description: 'Template not found',
  })
  async deleteTemplate(@Param('templateId') templateId: string): Promise<{ success: boolean; message: string }> {
    const result = await this.pesService.deleteTemplate(templateId);
    if (!result.success) {
      throw new NotFoundException(`Template with ID ${templateId} not found`);
    }
    return result;
  }

  // sending profile endpoints
  @Post('sending-profiles')
  @ApiBody({
    type: CreatePesSendingProfileDto,
    description: 'Create a new PES sending profile',
  })
  @ApiResponse({
    status: 201,
    description: 'Sending profile created successfully',
    type: PesSendingProfileResponseDto,
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  @ApiResponse({
    status: 500,
    description: 'Internal Server Error',
  })
  async createSendingProfile(@Body() dto: CreatePesSendingProfileDto): Promise<PesSendingProfileResponseDto> {
    return this.pesService.createSendingProfile(dto);
  }

  @Put('sending-profiles/:profileId')
  @ApiParam({
    name: 'profileId',
    description: 'ID of the sending profile to update',
    type: String,
  })
  @ApiBody({
    type: UpdatePesSendingProfileDto,
    description: 'Update an existing PES sending profile',
  })
  @ApiResponse({
    status: 200,
    description: 'Sending profile updated successfully',
    type: PesSendingProfileResponseDto,
  })
  async updateSendingProfile(@Param('profileId') profileId: string, @Body() dto: UpdatePesSendingProfileDto): Promise<PesSendingProfileResponseDto> {
    this.logger.log(`Updating sending profile with ID: ${profileId}`);
    return this.pesService.updateSendingProfile(profileId, dto);
  }

  @Post('sending-profiles/test-connection')
  @ApiBody({
    description: 'Test SMTP connection for sending profile',
    schema: {
      type: 'object',
      properties: {
        smtpHost: { type: 'string', example: 'smtp.example.com' },
        smtpPort: { type: 'number', example: 587 },
        smtpUsername: { type: 'string', example: 'smtp_user' },
        smtpPassword: { type: 'string', example: 'securepassword123' },
        smtpTls: { type: 'boolean', example: true },
      },
    },
  })
  @ApiResponse({
    status: 200,
    description: 'SMTP connection test successful',
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  @ApiResponse({
    status: 500,
    description: 'Internal Server Error',
  })
  async testSmtpConnection(@Body() smtpConfig: SMTPConnectionTestProp): Promise<{ success: boolean; message: string }> {
    return this.pesService.testSmtpConnection(smtpConfig);
  }

  @Get('sending-profiles/:profileId')
  @ApiParam({
    name: 'profileId',
    description: 'ID of the sending profile to retrieve',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'Sending profile retrieved successfully',
    type: PesSendingProfileResponseDto,
  })
  @ApiResponse({
    status: 404,
    description: 'Sending profile not found',
  })
  async getSendingProfileById(@Param('profileId') profileId: string): Promise<PesSendingProfileResponseDto> {
    this.logger.log(`Fetching sending profile with ID: ${profileId}`);
    const profile = await this.pesService.getSendingProfileById(profileId);
    if (!profile) {
      this.logger.error(`Sending profile with ID ${profileId} not found`);
      throw new NotFoundException(`Sending profile with ID ${profileId} not found`);
    }
    return profile;
  }

  // getting sending profiles by verified user ID
  @Get('sending-profiles/verified-user/:verifiedUserId')
  @ApiParam({
    name: 'verifiedUserId',
    description: 'ID of the verified user to get sending profiles for',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'List of sending profiles for the verified user',
    type: [PesSendingProfileResponseDto],
  })
  @ApiResponse({
    status: 404,
    description: 'No sending profiles found for the user',
  })
  async getSendingProfilesByVerifiedUserId(@Param('verifiedUserId') verifiedUserId: string): Promise<PesSendingProfileResponseDto[]> {
    this.logger.log(`Fetching sending profiles for verified user with ID: ${verifiedUserId}`);
    return this.pesService.getSendingProfilesByVerifiedUserId(verifiedUserId);
  }

  @Delete('sending-profiles/:profileId')
  @ApiParam({
    name: 'profileId',
    description: 'ID of the sending profile to delete',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'Sending profile deleted successfully',
  })
  @ApiResponse({
    status: 404,
    description: 'Sending profile not found',
  })
  async deleteSendingProfile(@Param('profileId') profileId: string): Promise<{ success: boolean; message: string }> {
    this.logger.log(`Deleting sending profile with ID: ${profileId}`);
    const result = await this.pesService.deleteSendingProfile(profileId);
    if (!result.success) {
      this.logger.error(`Failed to delete sending profile with ID ${profileId}`);
      throw new NotFoundException(`Sending profile with ID ${profileId} not found`);
    }
    return result;
  }

  // Campaigns methods
  @Get('campaigns/verified-user/:email')
  @UseGuards(JwtAuthGuard)
  @ApiParam({
    name: 'email',
    description: 'Email of the verified user to get campaigns for',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'List of campaigns for the verified user',
    type: [PesCampaignResponseDto],
  })
  @ApiResponse({
    status: 404,
    description: 'No campaigns found for the user',
  })
  @ApiResponse({
    status: 500,
    description: 'Internal Server Error',
  })
  async getCampaignsByVerifiedUserEmail(@Req() req: any): Promise<PesCampaignResponseDto[]> {
    const { user } = req;
    const email = user.email;
    this.logger.log(`Fetching campaigns for verified user with email: ${email}`);
    if (!email) {
      this.logger.error('No email found in user request');
      throw new BadRequestException('Email is required to fetch campaigns');
    }
    this.logger.log(`Fetching campaigns for verified user with email: ${email}`);
    return this.pesService.getCampaignByVerifiedUserEmail(email);
  }

  // Landing Page methods
  @Post('landing-pages')
  @ApiBody({
    type: CreatePesLandingPageDto,
    description: 'Create a new PES landing page',
  })
  @ApiResponse({
    status: 201,
    description: 'Landing page created successfully',
    type: PesLandingPageResponseDto,
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  @ApiResponse({
    status: 500,
    description: 'Internal Server Error',
  })
  async createLandingPage(@Body() dto: CreatePesLandingPageDto): Promise<PesLandingPageResponseDto> {
    return this.pesService.createLandingPage(dto);
  }

  @Get('landing-pages/:id')
  @ApiParam({
    name: 'id',
    description: 'ID of the landing page to retrieve',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'Landing page retrieved successfully',
    type: PesLandingPageResponseDto,
  })
  @ApiResponse({
    status: 404,
    description: 'Landing page not found',
  })
  async getLandingPageById(@Param('id') id: string): Promise<PesLandingPageResponseDto> {
    this.logger.log(`Fetching landing page with ID: ${id}`);
    const page = await this.pesService.getLandingPageById(id);
    if (!page) {
      this.logger.error(`Landing page with ID ${id} not found`);
      throw new NotFoundException(`Landing page with ID ${id} not found`);
    }
    return page;
  }

  @Get('landing-pages/verified-user/:verifiedUserId')
  @ApiParam({
    name: 'verifiedUserId',
    description: 'ID of the verified user to get landing pages for',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'List of landing pages for the verified user',
    type: [PesLandingPageResponseDto],
  })
  async getLandingPagesByVerifiedUserId(@Param('verifiedUserId') verifiedUserId: string): Promise<PesLandingPageResponseDto[]> {
    this.logger.log(`Fetching landing pages for verified user with ID: ${verifiedUserId}`);
    return this.pesService.getLandingPagesByVerifiedUserId(verifiedUserId);
  }

  @Put('landing-pages/:pageId')
  @ApiParam({
    name: 'pageId',
    description: 'ID of the landing page to update',
    type: String,
  })
  @ApiBody({
    type: UpdatePesLandingPageDto,
    description: 'Update an existing PES landing page',
  })
  @ApiResponse({
    status: 200,
    description: 'Landing page updated successfully',
    type: PesLandingPageResponseDto,
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  async updateLandingPage(@Param('pageId') pageId: string, @Body() dto: UpdatePesLandingPageDto): Promise<PesLandingPageResponseDto> {
    this.logger.log(`Updating landing page with ID: ${pageId}`);
    return this.pesService.updateLandingPage(pageId, dto);
  }

  @Delete('landing-pages/:pageId')
  @ApiParam({
    name: 'pageId',
    description: 'ID of the landing page to delete',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'Landing page deleted successfully',
  })
  @ApiResponse({
    status: 404,
    description: 'Landing page not found',
  })
  async deleteLandingPage(@Param('pageId') pageId: string): Promise<{ success: boolean; message: string }> {
    this.logger.log(`Deleting landing page with ID: ${pageId}`);
    const result = await this.pesService.deleteLandingPage(pageId);
    if (!result.success) {
      this.logger.error(`Failed to delete landing page with ID ${pageId}`);
      throw new NotFoundException(`Landing page with ID ${pageId} not found`);
    }
    return result;
  }

  // Recipient Group methods
  @Post('recipient-groups')
  @ApiBody({
    type: CreatePesRecipientGroupDto,
    description: 'Create a new PES recipient group',
  })
  @ApiResponse({
    status: 201,
    description: 'Recipient group created successfully',
    type: PesRecipientGroupResponseDto,
  })
  @ApiResponse({
    status: 400,
    description: 'Bad Request',
  })
  async createRecipientGroup(@Body() dto: CreatePesRecipientGroupDto): Promise<PesRecipientGroupResponseDto> {
    this.logger.log(`Creating PES recipient group with data: ${JSON.stringify(dto)}`);
    return this.pesService.createRecipientGroup(dto);
  }

  @Put('recipient-groups/:groupId/recipients')
  @ApiParam({
    name: 'groupId',
    description: 'ID of the recipient group to add recipients to',
    type: String,
  })
  @ApiBody({
    description: 'Add recipients email to a PES recipient group',
    type: [String],
    isArray: true,
    examples: {
      example1: {
        value: ['recipient1@example.com', 'recipient2@example.com'],
      },
    },
  })
  async addRecipientsToGroup(
    @Param('groupId') groupId: string,
    @Body('recipientsEmail') recipientsEmail: string[],
  ): Promise<PesRecipientGroupResponseDto> {
    this.logger.log(`Adding recipients to group with ID: ${groupId}`);
    return await this.pesService.addRecipientsToGroup(groupId, recipientsEmail);
  }

  // remove recipients from group
  @Delete('recipient-groups/:groupId/recipients')
  @ApiParam({
    name: 'groupId',
    description: 'ID of the recipient group to remove recipients from',
    type: String,
  })
  @ApiBody({
    description: 'Remove recipients email from a PES recipient group',
    type: String,
  })
  async removeRecipientsFromGroup(
    @Param('groupId') groupId: string,
    @Body('recipientsEmail') recipientsEmail: string[],
  ): Promise<PesRecipientGroupResponseDto> {
    this.logger.log(`Removing recipients from group with ID: ${groupId}`);
    return await this.pesService.removeRecipientsFromGroup(groupId, recipientsEmail);
  }

  // remove recipient group
  @Delete('recipient-groups/:groupId/verified-user/:verifiedUserId')
  @ApiParam({
    name: 'groupId',
    description: 'ID of the recipient group to delete',
    type: String,
  })
  @ApiParam({
    name: 'verifiedUserId',
    description: 'ID of the verified user who owns the recipient group',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'Recipient group deleted successfully',
  })
  @ApiResponse({
    status: 404,
    description: 'Recipient group not found',
  })
  async deleteRecipientGroup(
    @Param('groupId') groupId: string,
    @Param('verifiedUserId') verifiedUserId: string,
  ): Promise<PesRecipientGroupResponseDto[]> {
    this.logger.log(`Deleting recipient group with ID: ${groupId} for verified user ID: ${verifiedUserId}`);
    const result = await this.pesService.removeRecipientGroup(groupId, verifiedUserId);
    if (!result) {
      this.logger.error(`Recipient group with ID ${groupId} not found`);
      throw new NotFoundException(`Recipient group with ID ${groupId} not found`);
    }
    return result;
  }

  @Get('recipient-groups/verified-user/:verifiedUserId')
  @ApiParam({
    name: 'verifiedUserId',
    description: 'ID of the verified user to get recipient groups for',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'List of recipient groups for the verified user',
    type: [PesRecipientGroupResponseDto],
  })
  async getRecipientGroupsByVerifiedUserId(@Param('verifiedUserId') verifiedUserId: string): Promise<PesRecipientGroupResponseDto[]> {
    this.logger.log(`Fetching recipient groups for verified user with ID: ${verifiedUserId}`);
    return this.pesService.getRecipientGroupByVerifiedUserId(verifiedUserId);
  }

  @Get('recipient-groups/:groupId')
  @ApiParam({
    name: 'groupId',
    description: 'ID of the recipient group to retrieve',
    type: String,
  })
  @ApiResponse({
    status: 200,
    description: 'Recipient group retrieved successfully',
    type: PesRecipientGroupResponseDto,
  })
  async getRecipientGroupById(@Param('groupId') groupId: string): Promise<PesRecipientGroupResponseDto> {
    this.logger.log(`Fetching recipient group with ID: ${groupId}`);
    const group = await this.pesService.getRecipientGroupById(groupId);
    if (!group) {
      this.logger.error(`Recipient group with ID ${groupId} not found`);
      throw new NotFoundException(`Recipient group with ID ${groupId} not found`);
    }
    return group;
  }
}
