import { Body, Controller, Delete, Get, Param, Post, Query, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { SendLobbyMessageDto } from './dto/send-lobby-message.dto';
import { LobbyService } from './lobby.service';

@ApiTags('Main Lobby')
@Controller('lobby')
export class LobbyController {
  constructor(private readonly lobbyService: LobbyService) {}

  @Get()
  getMainLobby() {
    return this.lobbyService.getMainLobby();
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard)
  @Get('messages')
  getLobbyHistory(@Query('room') room = 'lobby', @Query('limit') limit = '50') {
    return this.lobbyService.history(room, Number(limit) || 50);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard)
  @Post('messages')
  sendLobbyMessage(@Req() req, @Body() dto: SendLobbyMessageDto) {
    return this.lobbyService.sendMessage(req.user.userId || req.user.sub, dto);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard)
  @Delete('messages/:id')
  deleteLobbyMessage(@Req() req, @Param('id') id: string) {
    return this.lobbyService.removeMessage(id, req.user.userId || req.user.sub);
  }
}
