import {
  Controller,
  Get,
  Post,
  Put,
  Body,
  Param,
  Query,
  UseGuards,
  Request,
} from '@nestjs/common';
import { ReviewService } from './review.service';
import { CreateReviewDto, QueryReviewDto } from './dto/review.dto';
import { JwtAuthGuard } from '@/common/guards/jwt-auth.guard';

// 用户端评价接口
@Controller('app/reviews')
export class ReviewController {
  constructor(private readonly reviewService: ReviewService) {}

  // 提交评价（需登录）
  @Post('order')
  @UseGuards(JwtAuthGuard)
  async create(
    @Request() req,
    @Body() dto: CreateReviewDto,
  ) {
    return this.reviewService.createByOrderNo(req.user.sub, dto.orderNo, dto);
  }

  // 查询评价列表（公开）
  @Get()
  async list(@Query() query: QueryReviewDto) {
    return this.reviewService.findPublic(query);
  }

  // 检查订单是否已评价
  @Get('check/:orderNo')
  async checkOrder(@Param('orderNo') orderNo: string) {
    const review = await this.reviewService.findByOrderNo(orderNo);
    return { reviewed: !!review, review };
  }
}
