import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
  Query,
  UseGuards,
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { ApiBearerAuth } from '@nestjs/swagger'
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 { BranchService } from './branch.service'
import { CreateBranchDto } from './dto/create-branch.dto'
import { UpdateBranchDto } from './dto/update-branch.dto'

@ApiBearerAuth()
@Controller('branches')
@UseGuards(AuthGuard('jwt'), RolesGuard)
export class BranchController {
  constructor(private readonly service: BranchService) { }

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

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

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

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

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