import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Query } from '@nestjs/common';
import { FilterBatchService } from './filter-batch.service';
import { CreateFilterBatchDto } from './dto/create-filter-batch.dto';
import { UpdateFilterBatchDto } from './dto/update-filter-batch.dto';
import { ApiBearerAuth, ApiBody, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from 'src/guards/jwt-auth.guard';
import { RolesGuard } from 'src/guards/roles.guard';
import { Roles } from 'src/common/decorators/roles.decorator';
import { USER_ROLE } from '../users/users.constant';
import { ResponseMessage } from 'src/common/decorators/response_message.decorator';
import { PaginatedQueryDto } from 'src/common/builder/QueryBuilder.dto';

@ApiTags('Filter Batch Endpoints')
@Controller('filter-batch')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
export class FilterBatchController {
  constructor(private readonly filterBatchService: FilterBatchService) { }

  @Post('/create-batch')
  @ResponseMessage('Successfully created a new filter prompt')
  @Roles(USER_ROLE.super_admin)
  @ApiBody({ type: CreateFilterBatchDto })
  create(@Body() createFilterBatchDto: CreateFilterBatchDto) {
    return this.filterBatchService.create(createFilterBatchDto);
  }

  @Get('/get-all-batches')
  @ResponseMessage('Successfully fetched all filter batches')
  @Roles(USER_ROLE.super_admin)
  @ApiQuery({ type: PaginatedQueryDto })
  findAll(
    @Query() query: Record<string, unknown>,
  ) {
    return this.filterBatchService.findAll(query);
  }

  @Get('/get-batch-by-id/:id')
  @ResponseMessage('Successfully fetched the filter batch')
  @Roles(USER_ROLE.super_admin)
  @ApiParam({ name: 'id', required: true })
  findOne(@Param('id') id: string) {
    return this.filterBatchService.findOne(id);
  }

  @Patch('/update-batch/:id')
  @ResponseMessage('Successfully updated the filter batch')
  @Roles(USER_ROLE.super_admin)
  @ApiParam({ name: 'id', required: true })
  @ApiBody({ type: UpdateFilterBatchDto })
  update(@Param('id') id: string, @Body() updateFilterBatchDto: UpdateFilterBatchDto) {
    return this.filterBatchService.update(id, updateFilterBatchDto);
  }

  @Delete('/delete-batch/:id')
  @ResponseMessage('Successfully deleted the filter batch')
  @Roles(USER_ROLE.super_admin)
  @ApiParam({ name: 'id', required: true })
  remove(@Param('id') id: string) {
    return this.filterBatchService.remove(id);
  }
}
