import {
  Body,
  Controller,
  HttpCode,
  HttpStatus,
  Post,
  Req,
  UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { Roles } from 'src/roles/roles.decorator';
import { RoleEnum } from 'src/roles/roles.enum';
import { RolesGuard } from 'src/roles/roles.guard';
import { CreateTeamWalletTransactionDto } from './dto/create-team-wallet-transaction.dto';
import { TeamWalletTransactionsService } from './team-wallet-transactions.service';

@ApiTags('Transactions')
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'), RolesGuard)
@Controller({
  path: 'team-wallet-transactions',
  version: '1',
})
export class TeamWalletTransactionsController {
  constructor(
    private teamWalletTransactionsService: TeamWalletTransactionsService,
  ) {}

  @Roles([RoleEnum.admin, RoleEnum.user])
  @Post()
  @HttpCode(HttpStatus.CREATED)
  create(
    @Req() req,
    @Body() createTransactionDto: CreateTeamWalletTransactionDto,
  ) {
    const userId = req.user?.id;
    return this.teamWalletTransactionsService.create(
      createTransactionDto,
      userId,
    );
  }
}
