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

@ApiTags('job_type')
@ApiBearerAuth('access-token')
@Controller('job_type')
export class JobTypeController {
  constructor(private readonly jobTypeService: JobTypeService) {}
  @Public()
  @Get()
  @ApiOperation({ summary: 'Get all job types' })
  async findAll(): Promise<JobType[]> {
    return this.jobTypeService.findAll();
  }

  @Public()
  @Get('filtered')
  @ApiOperation({ summary: 'Get all job types 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.jobTypeService.findAllPaginated(
      Number(page || 1),
      Number(limit || 10),
    );
  }

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

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

  @Public()
  @Put(':id')
  @ApiOperation({ summary: 'Update job type' })
  @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<JobType> {
    return this.jobTypeService.update(id, body);
  }

  @Public()
  @Patch(':id')
  @ApiOperation({ summary: 'Patch job type' })
  @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<JobType> {
    return this.jobTypeService.update(id, body);
  }

  @Public()
  @Delete(':id')
  @ApiOperation({ summary: 'Delete job type' })
  @ApiParam({ name: 'id', type: Number })
  async remove(@Param('id') id: number): Promise<{ message: string }> {
    return this.jobTypeService.remove(id);
  }
}
