import { Controller, Post, Body, Get } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { MailService, ContactMailData } from './mail.service';
import { Public } from '../../common/decorators';
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';

class SendContactDto {
    @IsNotEmpty()
    @IsString()
    name: string;

    @IsEmail()
    email: string;

    @IsNotEmpty()
    @IsString()
    type: string;

    @IsNotEmpty()
    @IsString()
    details: string;

    @IsNotEmpty()
    @IsString()
    captchaId: string;

    @IsNotEmpty()
    @IsString()
    captchaAnswer: string;
}

@ApiTags('Mail')
@Controller('mail')
export class MailController {
    constructor(private readonly mailService: MailService) { }

    @Public()
    @Post('send')
    @ApiOperation({ summary: 'Send contact form message' })
    async sendContact(@Body() dto: SendContactDto) {
        return this.mailService.sendContactMail(dto);
    }

    @Public()
    @Get('captcha')
    @ApiOperation({ summary: 'Get a new math captcha' })
    async getCaptcha() {
        return this.mailService.generateCaptcha();
    }
}
