import { Body, Controller, Post, UseGuards } from '@nestjs/common';

import { OptionalAuthGuard } from 'src/jwt-auth/optional-auth.guard';
import { ShareByEMail, User } from 'src/models/db.model';
import { ErrorResponse, MailInfo } from '../models/main.model';
import { MailService } from './mail.service';

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

  @UseGuards(OptionalAuthGuard)
  @Post()
  async sendEMail(@Body() mailInfo: MailInfo): Promise<void | ErrorResponse> {
    if (mailInfo.listing) {
      return await this.mailService.sendInquiry(mailInfo);
    } else {
      return await this.mailService.sendRequest(mailInfo);
    }
  }
  @Post('verify-email')
  async sendVerificationEmail(@Body() data: { 
    email: string, 
    redirectConfig: {
      protocol: string,
      hostname: string,
      port?: number
    } 
  }): Promise<void | ErrorResponse> {
    return await this.mailService.sendVerificationEmail(data.email, data.redirectConfig);
  }
  @UseGuards(OptionalAuthGuard)
  @Post('subscriptionConfirmation')
  async sendSubscriptionConfirmation(@Body() user: User): Promise<void | ErrorResponse> {
    return await this.mailService.sendSubscriptionConfirmation(user);
  }

  @UseGuards(OptionalAuthGuard)
  @Post('send2Friend')
  async send2Friend(@Body() shareByEMail: ShareByEMail): Promise<void | ErrorResponse> {
    return await this.mailService.send2Friend(shareByEMail);
  }
}
