package com.bonus.core.menu.controller;

import com.bonus.common.core.domain.R;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.core.common.page.PageVO;
import com.bonus.core.menu.dto.MenuEvaluaOrderAddDTO;
import com.bonus.core.menu.dto.MenuEvaluaOrderPageDTO;
import com.bonus.core.menu.dto.OrderEvaluaCountDto;
import com.bonus.core.menu.service.MenuEvaluaOrderService;
import com.bonus.core.menu.vo.MenuEvaluaOrderPageMealDTO;
import com.bonus.core.menu.vo.MenuEvaluateOrderPageVO;
import com.bonus.framework.annotation.RequiresGuest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
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;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping({"/api/v1/applet/menuevaluaorder"})
@Api(
        value = "menuevaluaorder",
        tags = {"pfy_订单评价"}
)
public class MenuEvaluaOrderController {
    private static final Logger log = LoggerFactory.getLogger(MenuEvaluaOrderController.class);
    @Lazy
    @Resource
    private MenuEvaluaOrderService menuEvaluaOrderService;

    @PostMapping({"/page/meal"})
    @RequiresGuest
    @ApiOperation("获取指定餐品的评价列表")
    public AjaxResult getMenuEvaluaOrderPageByMeal(@RequestBody @Valid MenuEvaluaOrderPageMealDTO dto) {
        return AjaxResult.success(this.menuEvaluaOrderService.getMenuEvaluaOrderPageByMeal(dto));
    }

    @PostMapping({"/add"})
    @RequiresGuest
    @ApiOperation("新增订单评价")
    public R<Void> addMenuEvaluaOrder(@RequestBody @Valid MenuEvaluaOrderAddDTO request) {
        this.menuEvaluaOrderService.addMenuEvaluaOrder(request);
        return R.ok();
    }

    @PostMapping({"/page/evaluate/order"})
    @ApiOperation("获取评价列表")
    public PageVO<MenuEvaluateOrderPageVO> getMenuEvaluateOrderPagePc(@RequestBody MenuEvaluaOrderPageDTO request) {
        return this.menuEvaluaOrderService.getMenuEvaluateOrderPagePc(request);
    }

    @PostMapping({"/evaluate/count"})
    @ApiOperation("获取订单评价数量")
    public OrderEvaluaCountDto getCustCount(@RequestBody OrderEvaluaCountDto dto) {
        return this.menuEvaluaOrderService.getHaveImageCount(dto.getDishesId());
    }
}
