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

@ApiTags('jobLevel')
@ApiBearerAuth('access-token')
@Controller('jobLevel')
export class JobLevelController {
  constructor(private readonly jobLevelService: JobLevelService) {}

  @Public()
  @Get()
  @ApiOperation({ summary: 'Get all job levels' })
  async findAll(): Promise<JobLevel[]> {
    return this.jobLevelService.findAll();
  }

  @Public()
  @Get('filtered')
  @ApiOperation({ summary: 'Get all job levels paginated' })
  @ApiQuery({ name: 'page', required: false, type: Number })
  @ApiQuery({ name: 'limit', required: false, type: Number })
  findAllPaginated(
    @Query('page') page: number = 1,
    @Query('limit') limit: number = 10,
  ) {
    return this.jobLevelService.findAllPaginated(
      Number(page || 1),
      Number(limit || 10),
    );
  }

  @Public()
  @Get(':id')
  @ApiOperation({ summary: 'Get job level by id' })
  @ApiParam({ name: 'id', type: Number })
  async findOne(@Param('id') id: number): Promise<JobLevel> {
    return this.jobLevelService.findOne(id);
  }

  @Public()
  @Post()
  @ApiOperation({ summary: 'Create job level' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: {
        name: { type: 'string' },
        status: { type: 'number', example: 1 },
      },
      required: ['name'],
    },
  })
  async create(@Body() body: any): Promise<JobLevel> {
    return this.jobLevelService.create(body);
  }

  @Public()
  @Put(':id')
  @ApiOperation({ summary: 'Update job level' })
  @ApiParam({ name: 'id', type: Number })
  @ApiBody({
    schema: {
      type: 'object',
      properties: {
        name: { type: 'string' },
        status: { type: 'number', example: 1 },
      },
    },
  })
  async update(@Param('id') id: number, @Body() body: any): Promise<JobLevel> {
    return this.jobLevelService.update(id, body);
  }

  @Public()
  @Patch(':id')
  @ApiOperation({ summary: 'Patch job level' })
  @ApiParam({ name: 'id', type: Number })
  @ApiBody({
    schema: {
      type: 'object',
      properties: {
        name: { type: 'string' },
        status: { type: 'number', example: 1 },
      },
    },
  })
  async patch(@Param('id') id: number, @Body() body: any): Promise<JobLevel> {
    return this.jobLevelService.update(id, body);
  }

  @Public()
  @Delete(':id')
  @ApiOperation({ summary: 'Delete job level' })
  @ApiParam({ name: 'id', type: Number })
  async delete(@Param('id') id: number): Promise<void> {
    return this.jobLevelService.delete(id);
  }
}
