import { Body, Controller, Delete, Get, Param, Post, Put, Query, Request } from '@nestjs/common';
import { BlacklistService, CreateBlacklistDto, UpdateBlacklistDto } from './blacklist.service';

@Controller('blacklist')
export class BlacklistController {
  constructor(private svc: BlacklistService) {}

  @Get()
  findAll(@Request() req: any, @Query('status') status?: string, @Query('q') q?: string, @Query('page') page = '1', @Query('limit') limit = '20') {
    return this.svc.findAll(req.tenantSubdomain, { status, q, page: +page, limit: +limit });
  }

  @Get(':id')
  findOne(@Request() req: any, @Param('id') id: string) { return this.svc.findOne(req.tenantSubdomain, id); }

  @Post()
  create(@Request() req: any, @Body() dto: CreateBlacklistDto) {
    return this.svc.create(req.tenantSubdomain, dto, req.user?.id, req.user?.name);
  }

  @Put(':id')
  update(@Request() req: any, @Param('id') id: string, @Body() dto: UpdateBlacklistDto) {
    return this.svc.update(req.tenantSubdomain, id, dto);
  }

  @Post(':id/whitelist')
  whitelist(@Request() req: any, @Param('id') id: string, @Body() dto: any) {
    return this.svc.whitelist(req.tenantSubdomain, id, dto);
  }

  @Delete(':id')
  remove(@Request() req: any, @Param('id') id: string) { return this.svc.remove(req.tenantSubdomain, id); }
}
