import { Controller, Get, Post, Body, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { PlayersService } from './players.service';
import { PlayerActionDto } from './dto/player-action.dto';
import { CurrentTenant } from '../../common/decorators/current-tenant.decorator';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { RequirePermission } from '../../common/decorators/require-permission.decorator';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { PermissionsGuard } from '../../common/guards/permissions.guard';

@ApiTags('Players')
@ApiBearerAuth()
@Controller('players')
@UseGuards(JwtAuthGuard, PermissionsGuard)
export class PlayersController {
  constructor(private readonly playersService: PlayersService) {}

  @Get()
  @RequirePermission('players.view')
  @ApiOperation({ summary: 'Get recent players for this server' })
  async getPlayers(@CurrentTenant() licenseId: string) {
    return await this.playersService.getPlayers(licenseId);
  }

  @Post('action')
  @RequirePermission('players.moderate')
  @ApiOperation({ summary: 'Perform a moderation action on a player' })
  async performAction(
    @CurrentTenant() licenseId: string,
    @CurrentUser('sub') userId: string,
    @Body() dto: PlayerActionDto,
  ) {
    return await this.playersService.performAction(licenseId, userId, dto);
  }
}
