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

@ApiTags('languages')
@ApiBearerAuth('access-token')
@Controller('languages')
export class LanguagesController {
  constructor(private readonly languagesService: LanguagesService) {}

  @Public()
  @Get()
  @ApiOperation({ summary: 'Get all languages' })
  findAll() {
    return this.languagesService.findAll();
  }

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

  @Public()
  @Get(':id')
  @ApiOperation({ summary: 'Get language by id' })
  @ApiParam({ name: 'id', type: Number })
  findOne(@Param('id') id: string) {
    return this.languagesService.findOne(+id);
  }

  @Public()
  @Post()
  @ApiOperation({ summary: 'Create language' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { name: { type: 'string' } },
      required: ['name'],
    },
  })
  create(@Body() body: any) {
    return this.languagesService.create(body);
  }

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

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

  @Public()
  @Delete(':id')
  @ApiOperation({ summary: 'Delete language' })
  @ApiParam({ name: 'id', type: Number })
  remove(@Param('id') id: string) {
    return this.languagesService.remove(+id);
  }
}
