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

import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.canteen.core.menu.dto.AppletReserveCanteenDTO;
import com.bonus.canteen.core.menu.dto.AppletReserveRecipeDTO;
import com.bonus.canteen.core.menu.dto.AppletWeekCanteenDTO;
import com.bonus.canteen.core.menu.dto.AppletWeekRecipeDTO;
import com.bonus.canteen.core.menu.service.MenuRecipeService;
import com.bonus.canteen.core.menu.vo.AppletWeekCanteenVO;
import com.bonus.canteen.core.menu.vo.AppletWeekRecipeVO;
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.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/api/v2/applet/menurecipe")
public class AppletRecipeV2Controller extends BaseController {
   private static final Logger log = LoggerFactory.getLogger(AppletRecipeV2Controller.class);
   @Lazy
   @Autowired
   private MenuRecipeService menuRecipeService;

   @PostMapping({"/list/week/canteen"})
   @ApiOperation("获取一周菜谱食堂列表")
   public AjaxResult getWeekMealList(@RequestBody AppletWeekCanteenDTO appletWeekCanteenDTO) {
      try {
         if (StringUtils.isBlank(String.valueOf(appletWeekCanteenDTO.getCustId()))){
            return AjaxResult.error("客户id不能为空");
         }
         return AjaxResult.success(this.menuRecipeService.getWeekMealList(appletWeekCanteenDTO));
      } catch (Exception e) {
            log.error(e.toString(), e);
            return AjaxResult.error("获取一周菜谱食堂列表失败");
      }
   }

   @ApiOperation("获取一周菜谱详情")
   @GetMapping({"/week/recipe/detail"})
   public TableDataInfo getWeekRecipeDetailList(@Valid AppletWeekRecipeDTO content) {
      try {
         startPage();
         content.setApplyDate(LocalDate.parse(content.getDate()));
         return getDataTable(this.menuRecipeService.getWeekRecipeDetailList(content));
      } catch (Exception e) {
            log.error(e.toString(), e);
            return getDataTable(null);
      }

   }

   /**
    * @author jsk
    * @param content
    * @return
    */
   @ApiOperation("获取预定餐食堂列表")
   @GetMapping({"/list/reserve/canteen/shopstall"})
   public TableDataInfo getReserveMealCanteenList(@Valid AppletReserveCanteenDTO content) {
      try {
         startPage();
         return getDataTable(this.menuRecipeService.getReserveMealCanteenList(content));
      } catch (Exception e) {
         log.error(e.toString(), e);
         return getDataTable(null);
      }
   }
   /**
    * @author jsk
    * @param content
    * @return
    */
   @ApiOperation("获取预定餐菜谱详情")
   @PostMapping({"/reserve/recipe/detail"})
   public TableDataInfo getReserveRecipeDetailList(@RequestBody AppletReserveRecipeDTO content) {
      try {
         startPage();
         return getDataTable(this.menuRecipeService.getReserveRecipeDetailList(content));
      } catch (Exception e) {
         log.error(e.toString(), e);
         return getDataTable(null);
      }
   }

}
