import { Injectable, Logger } from '@nestjs/common';
import {
  MessageBody,
  SubscribeMessage,
  WebSocketGateway,
} from '@nestjs/websockets';

@WebSocketGateway({ cors: true })
@Injectable()
export class AppService {
  private readonly logger = new Logger(AppService.name);

  @SubscribeMessage('example-request')
  handleCustomEvent(@MessageBody() data: string): unknown {
    this.logger.debug(`Received request in backend with data: ${data}`);
    return {
      event: 'example-response',
      data: `Replying from backend, received data: ${data}`,
    };
  }
}
