import { Body, Controller, Get, Patch, Post, Req, UseGuards } from '@nestjs/common';
import type { Request } from 'express';
import { AuthenticatedUser } from '../auth/auth.types';
import { IntegrationsService } from './integrations.service';
import { AuthGuard } from '../common/auth.guard';
import { TestWhatsappConfigDto } from './dto/test-whatsapp-config.dto';
import { UpdateWhatsappConfigDto } from './dto/update-whatsapp-config.dto';

@UseGuards(AuthGuard)
@Controller('integrations')
export class IntegrationsController {
  constructor(private readonly integrationsService: IntegrationsService) {}

  @Get('whatsapp')
  getWhatsappSettings() {
    return this.integrationsService.getWhatsappSettings();
  }

  @Patch('whatsapp')
  updateWhatsappSettings(
    @Req() request: Request & { user: AuthenticatedUser },
    @Body() dto: UpdateWhatsappConfigDto,
  ) {
    return this.integrationsService.updateWhatsappSettings(dto, request.user, request.ip);
  }

  @Post('whatsapp/test')
  testWhatsappSettings(
    @Req() request: Request & { user: AuthenticatedUser },
    @Body() dto: TestWhatsappConfigDto,
  ) {
    return this.integrationsService.testWhatsappSettings(dto, request.user, request.ip);
  }
}
