package com.gree.mall.miniapp.controller.order;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.miniapp.bean.goods.GoodsComment;
import com.gree.mall.miniapp.bean.goods.GoodsCommentCount;
import com.gree.mall.miniapp.bean.order.OrderCommentBean;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.order.OrderCommentLogic;
import com.gree.mall.miniapp.plus.entity.CommentTag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Slf4j
@RestController
@Api(value = "订单评价", tags ={"订单评价"} )
@RequestMapping(value = "/order/comment", produces = "application/json; charset=utf-8")
public class OrderCommentController {

    @Autowired
    OrderCommentLogic orderCommentLogic;

    @PostMapping("/add")
    @ApiOperation("评价")
    public ResponseHelper add(
            HttpServletRequest request,
            @RequestBody OrderCommentBean orderCommentBean
    ) throws RemoteServiceException {
        orderCommentLogic.add(request , orderCommentBean);
        return ResponseHelper.success();
    }

    @GetMapping("/tag/list")
    @ApiOperation("评价标签列表")
    public ResponseHelper<List<CommentTag>> tagList(HttpServletRequest request) throws RemoteServiceException {
        List<CommentTag> list = orderCommentLogic.list(request);
        return ResponseHelper.success(list);
    }


    @GetMapping("/goods")
    @ApiOperation("商品的评价列表")
    public ResponseHelper<IPage<GoodsComment>> goods(
            HttpServletRequest request,
            @ApiParam(value = "商品id",required = true) @RequestParam(required = true) String goodsId,
            @ApiParam(value = "标签名",required = false) @RequestParam(required = false) String tag,
            @ApiParam(value = "页号",required = true) @RequestParam(required = true) Integer pageNo,
            @ApiParam(value = "页大小",required = true) @RequestParam(required = true) Integer pageSize
    ) throws RemoteServiceException {
        IPage<GoodsComment> goodsCommentIPage = orderCommentLogic.goodsCommentList(request , goodsId, tag, pageNo, pageSize);
        return ResponseHelper.success(goodsCommentIPage);
    }

    @GetMapping("/goods/count")
    @ApiOperation("商品的评价汇总")
    public ResponseHelper<GoodsCommentCount> goodsCount(
            HttpServletRequest request,
            @ApiParam(value = "商品id",required = true) @RequestParam(required = true) String goodsId
    ) throws RemoteServiceException {
        GoodsCommentCount goodsCommentCount = orderCommentLogic.goodsCommentCount(request, goodsId);
        return ResponseHelper.success(goodsCommentCount);
    }


}
