import {
  Body,
  Controller,
  Get,
  Param,
  Post,
  Req,
  UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth } from '@nestjs/swagger';
import { Roles } from 'src/roles/roles.decorator';
import { RolesGuard } from 'src/roles/roles.guard';
import { CreatePenaltyDTO } from './dto/create-penalty.dto';
import { PenaltyService } from './penalty.service';

@ApiBearerAuth()
@Controller({
  path: 'penalty',
  version: '1',
})
export class PenaltyController {
  constructor(private service: PenaltyService) {}

  @Roles([])
  @Get()
  getIt(@Req() req: any) {
    const userId = req.user?.id;
    return this.service.getAll(userId);
  }

  @Roles([])
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  @Get(':id')
  getTeams(@Param('id') teamId: string) {
    return this.service.getTeamPenalties(teamId);
  }

  @UseGuards(AuthGuard('jwt'), RolesGuard)
  @Post()
  createPenalty(@Req() req: any, @Body() createPenaltyDto: CreatePenaltyDTO) {
    const userId = req.user?.id;
    return this.service.createPenalty(createPenaltyDto, userId);
  }
}
