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

@ApiTags('experiences')
@ApiBearerAuth('access-token')
@Controller('experiences')
export class ExperienceController {
  constructor(private readonly experienceService: ExperienceService) {}
  @Public()
  @Get()
  @ApiOperation({ summary: 'Get all experience levels' })
  findAll() {
    return this.experienceService.findAll();
  }

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

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

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

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

  @Public()
  @Patch(':id')
  @ApiOperation({ summary: 'Patch Experience Level' })
  @ApiParam({ name: 'id', type: Number })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { name: { type: 'string' }, code: { type: 'string' } },
    },
  })
  patch(@Param('id') id: number, @Body() body: any) {
    return this.experienceService.update(id, body);
  }

  @Public()
  @Delete(':id')
  @ApiOperation({ summary: 'Delete experience level' })
  @ApiParam({ name: 'id', type: Number })
  remove(@Param('id') id: number) {
    return this.experienceService.remove(id);
  }
}
