import { Body, Controller, Get, Headers, Post, Query } from '@nestjs/common';
import { MessagingService } from './messaging.service';

@Controller('messaging')
export class MessagingController {
  constructor(private readonly messagingService: MessagingService) {}

  @Get('webhooks/wascript')
  async wascriptHandshake() {
    const provider = await this.messagingService.getWascriptProviderStatus();
    return {
      status: 'ok',
      provider: 'wascript',
      webhookEnabled: provider.webhookConfigured,
    };
  }

  @Post('webhooks/wascript')
  wascriptWebhook(
    @Body() body: Record<string, unknown>,
    @Headers() headers: Record<string, string | string[] | undefined>,
    @Query() query: Record<string, string | string[] | undefined>,
  ) {
    return this.messagingService.handleWascriptWebhook(body, headers, query);
  }
}
