import { Body, Controller, Delete, Get, Param, Patch, Post, UseGuards } from '@nestjs/common';
import { DepartmentsService } from './departments.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@Controller('hr/departments')
@UseGuards(JwtAuthGuard)
export class DepartmentsController {
  constructor(private service: DepartmentsService) {}

  @Get()
  findAll() {
    return this.service.findAll();
  }

  @Get(':id')
  findById(@Param('id') id: string) {
    return this.service.findById(parseInt(id, 10));
  }

  @Post()
  create(@Body() body: { name: string; code?: string; description?: string }) {
    return this.service.create(body);
  }

  @Patch(':id')
  update(
    @Param('id') id: string,
    @Body() body: { name?: string; code?: string; description?: string },
  ) {
    return this.service.update(parseInt(id, 10), body);
  }

  @Delete(':id')
  delete(@Param('id') id: string) {
    return this.service.delete(parseInt(id, 10));
  }
}
