import { Controller, Post, Body, HttpCode, HttpStatus } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiBody } from '@nestjs/swagger';
import { SmsService } from './sms.service';
import { SendSmsDto, SendBulkSmsDto } from './dto/send-sms.dto';

@ApiTags('SMS')
@Controller('sms')
export class SmsController {
  constructor(private readonly smsService: SmsService) {}

  @Post('send')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: 'Send a single SMS via Twilio' })
  @ApiBody({ type: SendSmsDto })
  @ApiResponse({
    status: 200,
    description: 'SMS sent successfully',
    schema: {
      type: 'object',
      properties: {
        messageId: { type: 'string' },
        status: { type: 'string' },
      },
    },
  })
  @ApiResponse({
    status: 400,
    description: 'Bad request - invalid phone number or message',
  })
  @ApiResponse({
    status: 500,
    description: 'Internal server error - SMS sending failed',
  })
  async sendSms(@Body() sendSmsDto: SendSmsDto) {
    return await this.smsService.sendSms(sendSmsDto);
  }

  @Post('send-bulk')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: 'Send multiple SMS via Twilio' })
  @ApiBody({ type: SendBulkSmsDto })
  @ApiResponse({
    status: 200,
    description: 'Bulk SMS processing completed',
    schema: {
      type: 'array',
      items: {
        type: 'object',
        properties: {
          messageId: { type: 'string' },
          status: { type: 'string' },
        },
      },
    },
  })
  @ApiResponse({
    status: 400,
    description: 'Bad request - invalid SMS data',
  })
  @ApiResponse({
    status: 500,
    description: 'Internal server error - SMS sending failed',
  })
  async sendBulkSms(@Body() sendBulkSmsDto: SendBulkSmsDto) {
    return await this.smsService.sendBulkSms(sendBulkSmsDto.smsList);
  }
}
