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

@ApiTags('房源审核(管理员)')
@Controller('admin/rooms')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@ApiBearerAuth()
export class AdminRoomController {
  constructor(private readonly adminRoomService: AdminRoomService) {}

  @Get()
  @ApiOperation({ summary: '房源列表(管理员)' })
  async findAll(@Query() query: QueryRoomDto) {
    return await this.adminRoomService.findAllForAdmin(query);
  }

  @Put(':id/approve')
  @ApiOperation({ summary: '审核通过' })
  async approve(@Param('id') id: number) {
    return await this.adminRoomService.approve(Number(id));
  }

  @Put(':id/reject')
  @ApiOperation({ summary: '审核拒绝' })
  async reject(@Param('id') id: number, @Body('reason') reason: string) {
    return await this.adminRoomService.reject(Number(id), reason);
  }
}
