package com.campus.activity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.campus.activity.common.Result;
import com.campus.activity.dto.request.ReviewRequest;
import com.campus.activity.entity.Review;
import com.campus.activity.service.ReviewService;
import com.campus.activity.vo.ReviewVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "评价模块", description = "活动评价相关接口")
@RestController
@RequestMapping("/api/v1/reviews")
@RequiredArgsConstructor
public class ReviewController {

    private final ReviewService reviewService;

    @Operation(summary = "提交评价")
    @PostMapping
    public Result<ReviewVO> createReview(@Valid @RequestBody ReviewRequest request) {
        ReviewVO reviewVO = reviewService.createReview(request);
        return Result.success("评价成功", reviewVO);
    }

    @Operation(summary = "获取活动评价列表")
    @GetMapping("/activity/{activityId}")
    public Result<IPage<ReviewVO>> getActivityReviews(
            @PathVariable Long activityId,
            @RequestParam(defaultValue = "1") Long current,
            @RequestParam(defaultValue = "10") Long size) {
        Page<Review> page = new Page<>(current, size);
        IPage<ReviewVO> result = reviewService.getActivityReviews(page, activityId);
        return Result.success(result);
    }

    @Operation(summary = "获取我的评价列表")
    @GetMapping("/my")
    public Result<IPage<ReviewVO>> getMyReviews(
            @RequestParam(defaultValue = "1") Long current,
            @RequestParam(defaultValue = "10") Long size) {
        Page<Review> page = new Page<>(current, size);
        IPage<ReviewVO> result = reviewService.getMyReviews(page);
        return Result.success(result);
    }
}