import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
  Query,
  UseGuards,
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { Roles } from 'src/auth/decorators/roles.decorator'
import { RolesGuard } from 'src/auth/guards/roles.guard'
import { BootstrapTableRequestDto } from 'src/commons/dto/bootstrap-table-request.dto'
import { CreateRoleDto } from './create-role.dto'
import { UpdateRoleDto } from './update-role.dto'
import { RoleService } from './role.service'

@Controller('roles')
@UseGuards(AuthGuard('jwt'), RolesGuard)
export class RoleController {
  constructor(private readonly service: RoleService) {}

  @Get()
  @Roles('SUPER_ADMIN')
  findAll(@Query() query: BootstrapTableRequestDto) {
    return this.service.findAll(query)
  }

  @Get(':id')
  @Roles('SUPER_ADMIN')
  findOne(@Param('id') id: string) {
    return this.service.findOne(id)
  }

  @Post()
  @Roles('SUPER_ADMIN')
  create(@Body() dto: CreateRoleDto) {
    return this.service.create(dto)
  }

  @Patch(':id')
  @Roles('SUPER_ADMIN')
  update(@Param('id') id: string, @Body() dto: UpdateRoleDto) {
    return this.service.update(id, dto)
  }

  @Delete(':id')
  @Roles('SUPER_ADMIN')
  remove(@Param('id') id: string) {
    return this.service.remove(id)
  }
}