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

@ApiTags('评价审核(管理员)')
@Controller('admin/reviews')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@ApiBearerAuth()
export class AdminReviewController {
  constructor(private readonly adminReviewService: AdminReviewService) {}

  @Get()
  @ApiOperation({ summary: '评价审核列表' })
  async list(@Query() query: QueryReviewDto) {
    return this.adminReviewService.findAllForAdmin(query);
  }

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

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