import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Param,
  Body,
  Query,
  Patch,
} from '@nestjs/common';
import { RoleLevelsService } from './role_levels.service';
import { Public } from '../auth/public.decorator';
import {
  ApiBearerAuth,
  ApiTags,
  ApiBody,
  ApiParam,
  ApiQuery,
  ApiOperation,
} from '@nestjs/swagger';

@ApiTags('role_levels')
@ApiBearerAuth('access-token')
@Controller('role_levels')
export class RoleLevelsController {
  constructor(private readonly roleLevelsService: RoleLevelsService) {}
  @Public()
  @Get()
  @ApiOperation({ summary: 'Get all role levels' })
  findAll() {
    return this.roleLevelsService.findAll();
  }

  @Public()
  @Get('filtered')
  @ApiOperation({ summary: 'Get Role Levels Paginated' })
  @ApiQuery({ name: 'page', required: false, type: Number })
  @ApiQuery({ name: 'limit', required: false, type: Number })
  @ApiQuery({ name: 'industry_id', required: false, type: Number })
  findAllPaginated(
    @Query('page') page: number = 1,
    @Query('limit') limit: number = 10,
    @Query('industry_id') industryId?: number,
  ) {
    return this.roleLevelsService.findAllPaginated(
      Number(page || 1),
      Number(limit || 10),
      industryId ? Number(industryId) : undefined,
    );
  }

  @Public()
  @Get('/with_counts')
  @ApiOperation({ summary: 'Get role levels with counts' })
  async getRoleLevelsWithCounts() {
    return this.roleLevelsService.getRoleLevelsWithCounts();
  }

  @Public()
  @Get(':id')
  @ApiOperation({ summary: 'Get role level by ID' })
  @ApiParam({ name: 'id', type: Number })
  findOne(@Param('id') id: number) {
    return this.roleLevelsService.findOne(id);
  }

  @Public()
  @Post()
  @ApiOperation({ summary: 'Create Role Level' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { name: { type: 'string' }, industry_id: { type: 'number' } },
    },
  })
  create(@Body() body: any) {
    return this.roleLevelsService.create(body);
  }

  @Public()
  @Put(':id')
  @ApiOperation({ summary: 'Update Role Level' })
  @ApiParam({ name: 'id', type: Number })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { name: { type: 'string' }, industry_id: { type: 'number' } },
    },
  })
  update(@Param('id') id: number, @Body() body: any) {
    return this.roleLevelsService.update(id, body);
  }

  @Public()
  @Patch(':id')
  @ApiOperation({ summary: 'Patch Role Level' })
  @ApiParam({ name: 'id', type: Number })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { name: { type: 'string' }, industry_id: { type: 'number' } },
    },
  })
  patch(@Param('id') id: number, @Body() body: any) {
    return this.roleLevelsService.update(id, body);
  }
  @Public()
  @Delete(':id')
  @ApiOperation({ summary: 'Delete role level' })
  @ApiParam({ name: 'id', type: Number })
  remove(@Param('id') id: number) {
    return this.roleLevelsService.remove(id);
  }
}
