import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Patch,
  Post,
  Query,
  UseGuards,
} from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiOperation,
  ApiQuery,
  ApiTags,
} from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { PositionsService } from './positions.service';
import { CreatePositionDto } from './dto/create-position.dto';
import { UpdatePositionDto } from './dto/update-position.dto';

@ApiTags('positions')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('positions')
export class PositionsController {
  constructor(private readonly service: PositionsService) {}

  @Get()
  @ApiOperation({ summary: 'List positions (optionally filtered)' })
  @ApiQuery({ name: 'countryId', required: false, type: Number })
  @ApiQuery({ name: 'categoryId', required: false, type: Number })
  findAll(
    @Query('countryId') countryId?: string,
    @Query('categoryId') categoryId?: string,
  ) {
    return this.service.findAll({
      countryId: countryId ? BigInt(countryId) : undefined,
      categoryId: categoryId ? BigInt(categoryId) : undefined,
    });
  }

  @Get(':id')
  @ApiOperation({ summary: 'Get one position' })
  findOne(@Param('id', ParseIntPipe) id: string) {
    return this.service.findOne(BigInt(id));
  }

  @Post()
  @ApiOperation({ summary: 'Create a position' })
  create(@Body() dto: CreatePositionDto) {
    return this.service.create(dto);
  }

  @Patch(':id')
  @ApiOperation({ summary: 'Update a position' })
  update(
    @Param('id', ParseIntPipe) id: string,
    @Body() dto: UpdatePositionDto,
  ) {
    return this.service.update(BigInt(id), dto);
  }

  @Delete(':id')
  @ApiOperation({ summary: 'Delete a position' })
  remove(@Param('id', ParseIntPipe) id: string) {
    return this.service.remove(BigInt(id));
  }
}
