import {
  Controller,
  Get,
  Post,
  Patch,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
} from '@nestjs/common';
import { VipsService } from './vips.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { AbilitiesGuard } from '../auth/guards/abilities.guard';
import { CanCreate, CanRead, CanUpdate, CanDelete } from '../auth/decorators/check-ability.decorator';
import { CreateVipDto, UpdateVipDto } from './dto';

@Controller('vips')
@UseGuards(JwtAuthGuard, AbilitiesGuard)
export class VipsController {
  constructor(private readonly vipsService: VipsService) {}

  @Post()
  @CanCreate('VIP')
  create(@Body() createVipDto: CreateVipDto) {
    return this.vipsService.create(createVipDto);
  }

  @Get()
  @CanRead('VIP')
  findAll() {
    return this.vipsService.findAll();
  }

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

  @Patch(':id')
  @CanUpdate('VIP')
  update(@Param('id') id: string, @Body() updateVipDto: UpdateVipDto) {
    return this.vipsService.update(id, updateVipDto);
  }

  @Delete(':id')
  @CanDelete('VIP')
  remove(
    @Param('id') id: string,
    @Query('hard') hard?: string,
  ) {
    // Only administrators can hard delete
    const isHardDelete = hard === 'true';
    return this.vipsService.remove(id, isHardDelete);
  }
}
