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

@ApiTags('companySuggestions')
@ApiBearerAuth('access-token')
@Controller('companySuggestions')
export class CompanySuggestionsController {
  constructor(private readonly service: CompanySuggestionsService) {}

  @Public()
  @Get('search')
  @ApiOperation({ summary: 'Search Company Suggestions' })
  @ApiQuery({ name: 'q', required: true, type: String })
  async search(@Query('q') query: string) {
    return this.service.suggestCompanies(query);
  }

  @Public()
  @Post()
  @ApiOperation({ summary: 'Create Company Suggestion' })
  @ApiBody({ schema: { type: 'object', description: 'Suggestion data' } })
  create(@Body() body: any) {
    return this.service.create(body);
  }

  @Public()
  @Put(':id')
  @ApiOperation({ summary: 'Update Company Suggestion' })
  @ApiParam({ name: 'id', type: String })
  @ApiBody({ schema: { type: 'object', description: 'Suggestion data' } })
  update(@Param('id') id: string, @Body() body: any) {
    return this.service.update(+id, body);
  }

  @Public()
  @Patch(':id')
  @ApiOperation({ summary: 'Patch Company Suggestion' })
  @ApiParam({ name: 'id', type: String })
  @ApiBody({ schema: { type: 'object', description: 'Suggestion data' } })
  patch(@Param('id') id: string, @Body() body: any) {
    return this.service.update(+id, body);
  }

  @Public()
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.service.remove(+id);
  }

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