package com.bonus.canteen.core.menu.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.canteen.core.menu.dto.MenuCollectionDishesDTO;
import com.bonus.canteen.core.menu.dto.MenuDeleteDishesDTO;
import com.bonus.canteen.core.menu.service.CollectionDishesService;
import com.bonus.canteen.core.menu.vo.MenuCollectionDishesVO;
import com.bonus.common.houqin.encrypt.RequiresGuest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping({"/api/v1/applet/collectionDishes"})
@Api(
   value = "appletCollectionStall",
   tags = {"wlk_小程序收藏菜品controller"}
)
public class AppletCollectionDishes extends BaseController {
   private static final Logger log = LoggerFactory.getLogger(AppletCollectionDishes.class);
   @Autowired
   @Lazy
   private CollectionDishesService collectionDishesService;

   @ApiOperation("收藏菜品")
   @PostMapping({"/collectionDishes"})
   @RequiresGuest
   public AjaxResult addCollectionDishes(@RequestBody MenuCollectionDishesDTO content) {
      try{
         this.collectionDishesService.addDishes(content);
         return success();
      }catch (Exception e){
         return error(e.getMessage());
      }
   }

   @PostMapping({"/dishesList"})
   @RequiresGuest
   @ApiOperation("获取收藏菜品列表")
   public AjaxResult queryDishesList(@RequestBody MenuCollectionDishesDTO content, Long custId) {
      //LeResponse<List<MenuCollectionDishesVO>>
      List<MenuCollectionDishesVO> menuCollectionDishesVoList = this.collectionDishesService.queryDishesList(content.getCustId(), content);
      return success(menuCollectionDishesVoList);
   }

   @PostMapping({"/deleteDishes"})
   @RequiresGuest
   @ApiOperation("删除收藏菜品")
   public AjaxResult deleteDishes(@RequestBody @Valid MenuDeleteDishesDTO content) {
      try{
         this.collectionDishesService.deleteDishesById(content);
         return success();
      }catch (Exception e){
         return error(e.getMessage());
      }
   }
}
