import { Controller, Get, Param, Patch, Post, Query, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { JwtPayload } from '../../common/interfaces/jwt-payload.interface';
import { BlockListQueryDto } from './dto/block-list-query.dto';
import { BlocksService } from './blocks.service';

@ApiTags('Blocks')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('blocks')
export class BlocksController {
  constructor(private readonly blocksService: BlocksService) {}

  @Get()
  async list(@CurrentUser() user: JwtPayload, @Query() query: BlockListQueryDto) {
    return this.blocksService.listBlockedUsers(user.sub, query);
  }

  @Post(':targetUserId')
  async block(@CurrentUser() user: JwtPayload, @Param('targetUserId') targetUserId: string) {
    return this.blocksService.block(user.sub, targetUserId);
  }

  @Patch(':targetUserId/unblock')
  async unblock(@CurrentUser() user: JwtPayload, @Param('targetUserId') targetUserId: string) {
    return this.blocksService.unblock(user.sub, targetUserId);
  }

  @Get('status/:targetUserId')
  async status(@CurrentUser() user: JwtPayload, @Param('targetUserId') targetUserId: string) {
    return this.blocksService.getStatus(user.sub, targetUserId);
  }
}
