import { Controller, Post, Body, UseGuards } from '@nestjs/common';
import { WhatsappService } from './whatsapp.service';
import { AuthGuard } from '@nestjs/passport';
import { IsString, IsNotEmpty } from 'class-validator';

class SendGreetingDto {
  @IsString()
  @IsNotEmpty()
  to: string;

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

@Controller('whatsapp')
@UseGuards(AuthGuard('jwt'))
export class WhatsappController {
  constructor(private readonly whatsappService: WhatsappService) { }

  @Post('send-greeting')
  sendGreeting(@Body() dto: SendGreetingDto) {
    return this.whatsappService.sendGreeting(dto.to, dto.clientName);
  }

  @Post('templates')
  registerTemplate(@Body() data: { type: string, templateName: string, language?: string, body?: string }) {
    return this.whatsappService.upsertTemplate(data);
  }
}
