import {
  Controller,
  Get,
  Put,
  Param,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { UserService } from './user.service';
import { JwtAuthGuard, RolesGuard } from '@/common';
import { Roles } from '@/common/decorators/roles.decorator';
import { QueryUserDto } from './dto/user.dto';

@ApiTags('用户管理(管理员)')
@Controller('admin/users')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@ApiBearerAuth()
export class UserAdminController {
  constructor(private readonly userService: UserService) {}

  @Get()
  @ApiOperation({ summary: '获取用户列表' })
  async findAll(@Query() query: QueryUserDto) {
    return this.userService.findAll(query);
  }

  @Put(':id/freeze')
  @ApiOperation({ summary: '冻结用户' })
  async freeze(@Param('id') id: number) {
    return this.userService.freeze(id);
  }

  @Put(':id/unfreeze')
  @ApiOperation({ summary: '解冻用户' })
  async unfreeze(@Param('id') id: number) {
    return this.userService.unfreeze(id);
  }
}
