package com.ylx.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.common.core.domain.R;
import com.ylx.order.domain.dto.MerchantMyCommentQueryDTO;
import com.ylx.order.domain.vo.MerchantCompositeScoreVO;
import com.ylx.order.domain.vo.MerchantMyCommentVO;
import com.ylx.order.service.TCommentUserService;
import com.ylx.order.domain.dto.OrderCommentDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类描述：订单评论控制器
 *
 * @author Administrator
 * @version 1.0
 * @date 2026/6/9 15:59
 */

@Api(tags = "订单评论")
@Slf4j
@RestController
@RequestMapping("/order/comment")
@RequiredArgsConstructor
public class OrderCommentController {

    private final TCommentUserService tCommentUserService;

    @ApiOperation("提交评论（用户评论技师）")
    @PostMapping("/submit")
    public R<?> submitComment(@Validated  @RequestBody OrderCommentDTO dto) {
        tCommentUserService.submitComment(dto);
        return R.ok("评价完成");
    }

    /**
     * 商户端我的评分分页查询
     *
     * @param dto
     * @return R<Page<MerchantMyCommentVO>>
     */
    @ApiOperation("商户端我的评分分页查询")
    @PostMapping("/merchant/my/page")
    public R<Page<MerchantMyCommentVO>> getMerchantMyCommentPage(@Validated @RequestBody MerchantMyCommentQueryDTO dto) {
        try {
            return R.ok(tCommentUserService.getMerchantMyCommentPage(dto));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 查询商户的综合评分
     *
     * @return R<MerchantCompositeScoreVO>
     */
    @ApiOperation("查询商户的综合评分")
    @GetMapping("/merchant/my/score")
    public R<MerchantCompositeScoreVO> getMerchantCompositeScore() {
        try {
            return R.ok(tCommentUserService.getMerchantCompositeScore());
        } catch (Exception e) {
            log.error("查询商户综合评分失败", e);
            return R.fail("查询商户综合评分失败");
        }
    }

}
