import { Controller, Post, Body, Req } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import type { Request } from 'express';
import { SmsService } from './sms.service';
import { SendSmsCodeDto } from './sms.dto';
import { Public } from '../../../shared/common/decorators';
import { jsonResponse } from '../../../shared/common/filters';
import { getClientIp } from '../../../shared/common/client-ip.util';

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

  @Public()
  @Post('player/sms/send')
  async send(@Body() dto: SendSmsCodeDto, @Req() req: Request) {
    const result = await this.sms.sendVerifyCode({
      phone: dto.phone.trim(),
      countryCode: dto.countryCode.trim(),
      locale: dto.locale,
      clientIp: getClientIp(req),
      purpose: dto.purpose,
    });
    return jsonResponse(result);
  }
}
