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

@ApiTags('industries')
@ApiBearerAuth('access-token')
@Controller('industries')
export class IndustriesController {
  constructor(private readonly industriesService: IndustriesService) {}
  @Public()
  @Get()
  @ApiOperation({ summary: 'Get all industries' })
  findAll() {
    return this.industriesService.findAll();
  }

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

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

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

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

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

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