import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Request } from '@nestjs/common';
import { IncentivesService } from './incentives.service';
import { CreateIncentiveDto } from './dto/create-incentive.dto';
import { UpdateIncentiveDto } from './dto/update-incentive.dto';
import { AuthGuard } from '@nestjs/passport';

@Controller('incentives')
@UseGuards(AuthGuard('jwt'))
export class IncentivesController {
  constructor(private readonly incentivesService: IncentivesService) { }

  @Post()
  create(@Request() req, @Body() createIncentiveDto: CreateIncentiveDto) {
    if (!createIncentiveDto.userId) {
      createIncentiveDto.userId = req.user.id;
    }
    return this.incentivesService.create(createIncentiveDto);
  }

  @Get()
  findAll(@Request() req) {
    return this.incentivesService.findAll(req.user);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.incentivesService.findOne(id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateIncentiveDto: UpdateIncentiveDto) {
    return this.incentivesService.update(id, updateIncentiveDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.incentivesService.remove(id);
  }
}
