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

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bonus.canteen.core.menu.dto.CheckDishesDto;
import com.bonus.canteen.core.menu.dto.OrderRecipeDishesDto;
import com.bonus.canteen.core.menu.service.MenuRecipeDishesService;
import com.bonus.canteen.core.menu.vo.CheckDishesVo;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.lang.invoke.SerializedLambda;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Service
public class MenuRecipeApi {
   private static final Logger log = LoggerFactory.getLogger(MenuRecipeApi.class);
//   @Autowired
//   private MenuRecipeService menuRecipeService;
//   @Autowired
//   private MenuRecipeMapper menuRecipeMapper;
//   @Autowired
//   private MenuRecipeDetailService menuRecipeDetailService;
//   @Autowired
//   @Lazy
//   private MacMenuRecipeService macMenuRecipeService;
   @Autowired
   @Lazy
   private MenuRecipeDishesService menuRecipeDishesService;
//   @Autowired
//   private MenuAppRecipeMapper menuAppRecipeMapper;
//   @Autowired
//   private AndroidMenuService androidMenuService;
//   @Autowired
//   private MenuRecipeBindSortService menuRecipeBindSortService;

//   public List<RecipeQueryVO> queryAllRecipes(RecipeQueryDTO content) {
//      return this.menuRecipeService.queryAllRecipes(content);
//   }
//
//   public List<RecipeDishesQueryVO> queryRecipeDishes(RecipeDishesQueryDTO param) {
//      return this.menuRecipeService.queryRecipeDishes(param);
//   }
//
//   public MenuRecipe getById(Long recipeId) {
//      return (MenuRecipe)this.menuRecipeService.getOne((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(MenuRecipe.class).eq(MenuRecipe::getDelFlag, DelFlagEnum.DEL_FALSE.key())).eq(MenuRecipe::getRecipeId, recipeId));
//   }
//
//   public MenuRecipe getByRecipeId(Long recipeId) {
//      return (MenuRecipe)this.menuRecipeService.getOne((Wrapper)Wrappers.lambdaQuery(MenuRecipe.class).eq(MenuRecipe::getRecipeId, recipeId));
//   }
//
//   public Long saveRecipe(OpenMenuRecipeSyncDTO openMenuRecipeSyncDTO) {
//      return this.menuRecipeService.saveRecipe(openMenuRecipeSyncDTO);
//   }
//
//   public IssueRecipeResultVO issueRecipeListApi(IssueRecipeListDTO issueRecipeListDTO) {
//      return this.macMenuRecipeService.issueNoRecipeList(issueRecipeListDTO);
//   }
//
//   public IssueRecipeCompressVO issueRecipeV2Compress(IssueRecipeV2DTO issueRecipeV2DTO) {
//      return this.menuRecipeService.issueRecipeV2Compress(issueRecipeV2DTO);
//   }
//
//   public void androidAddRecipeDishes(AndroidAddRecipeDishesDTO content) {
//      this.menuRecipeService.androidAddRecipeDishes(content);
//   }
//
//   public void androidRemoveRecipeDishes(AndroidRemoveRecipeDishesDTO content) {
//      this.menuRecipeService.androidRemoveRecipeDishes(content);
//   }
//
//   public void editRecipeDeTailDishesPriceFeign(MenuEditRecipePriceDTO menuEditRecipePriceDTO) {
//      this.menuRecipeService.editRecipeDeTailDishesPriceFeign(menuEditRecipePriceDTO);
//   }
//
//   public boolean checkCanteenStallRelation(Long canteenId, Long stallId) {
//      return this.menuRecipeMapper.exists((Wrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(MenuRecipe.class).eq(ObjectUtil.isNotNull(canteenId), MenuRecipe::getCanteenId, canteenId)).eq(ObjectUtil.isNotNull(stallId), MenuRecipe::getStallId, stallId)).eq(MenuRecipe::getDelFlag, DelFlagEnum.DEL_FALSE.key()));
//   }
//
//   public List<Long> getRecipeIdListByCanteen(Long canteenId, String thirdCanteenId, Long stallId, String thirdStallId) {
//      return this.menuRecipeMapper.selectRecipeIdListByCanteen(canteenId, thirdCanteenId, stallId, thirdStallId);
//   }
//
//   public Long selectRecipeIdByPlanId(String planId) {
//      return this.menuRecipeMapper.selectRecipeIdByPlanId(planId);
//   }

   public OrderRecipeDishesDto getOrderDishesDetail(Long detailId, Long dishesId) {
      log.info("获取菜品价格请求参数detailId: {}, dishesId: {}", detailId, dishesId);
      return this.menuRecipeDishesService.getOrderDishesDetail(detailId, dishesId);
   }

//   public List<MenuRecipeDetail> selectMenuRecipeDetailByDetailId(List<Long> detailIds) {
//      return this.menuRecipeDetailService.list((Wrapper)Wrappers.lambdaQuery(MenuRecipeDetail.class).in(MenuRecipeDetail::getDetailId, detailIds));
//   }
//
//   public Long getStallBindRecipeId(Long stallId, Integer deviceType) {
//      MenuRecipeSortEnum sortEnum = this.getMenuRecipeSortEnum(deviceType);
//      if (sortEnum != null) {
//         List<Long> recipeIds = this.menuAppRecipeMapper.selectRecipeInSameShop(stallId, (Long)null, sortEnum.getBindType(), (Long)null);
//         if (ObjectUtil.isNotEmpty(recipeIds)) {
//            return (Long)recipeIds.get(0);
//         }
//      }
//
//      return null;
//   }
//
//   private MenuRecipeSortEnum getMenuRecipeSortEnum(Integer deviceType) {
//      MenuRecipeSortEnum sortEnum = null;
//      Map<Integer, MenuRecipeSortEnum> bindTypeMap = MenuRecipeSortEnum.getKeyMap();
//      Iterator var4 = bindTypeMap.entrySet().iterator();
//
//      while(var4.hasNext()) {
//         Map.Entry<Integer, MenuRecipeSortEnum> key = (Map.Entry)var4.next();
//         if (((MenuRecipeSortEnum)key.getValue()).getDeviceType().contains(deviceType)) {
//            sortEnum = (MenuRecipeSortEnum)key.getValue();
//            break;
//         }
//      }
//
//      return ObjectUtil.isEmpty(sortEnum) ? null : sortEnum;
//   }
//
//   public List<DeviceRecipeDTO> getBindByTypeAndStalls(List<DeviceBindDTO> deviceBindDTOS, Integer deviceType) {
//      MenuRecipeSortEnum sortEnum = this.getMenuRecipeSortEnum(deviceType);
//      return (List)(sortEnum != null && !ObjectUtil.isEmpty(deviceBindDTOS) ? this.menuAppRecipeMapper.getBindByTypeAndStalls(deviceBindDTOS, sortEnum.getBindType()) : new ArrayList());
//   }
//
//   public List<AndroidRecipeTypeDetailVO> getProductionMachineRecipe() {
//      return this.menuRecipeService.getProductionMachineRecipe();
//   }
//
//   public List<MenuSelfRecipeListVO> getAndroidRecipeListSelfTerminal(MenuSelfRecipeListDTO content) {
//      return this.androidMenuService.getAndroidRecipeListSelfTerminal(content);
//   }
//
//   public List<MenuSelfRecipeVO> getAndroidRecipeDetailSelfTerminal(Map<String, String> headers, MenuSelfRecipeDTO content) {
//      return this.androidMenuService.getAndroidRecipeDetailSelfTerminal(headers, content);
//   }
//
//   public List<AndroidGetRecipeDishesVO> androidGetRecipeDishes(AndroidGetRecipeDishesDTO content) {
//      return this.menuRecipeService.androidGetRecipeDishes(content);
//   }

   public List<CheckDishesVo> checkDishes(List<CheckDishesDto> checkDishes, Integer orderType) {
      return this.menuRecipeDishesService.checkDishes(checkDishes, orderType);
   }
//
//   public void deleteByDevice(Integer deviceType) {
//      this.menuRecipeBindSortService.deleteByDevice(deviceType);
//   }
//
//   public List<MenuRecipe> deviceSearchRecipe(DeviceSearchRecipeDto content) {
//      return this.menuRecipeService.list((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(MenuRecipe.class).eq(MenuRecipe::getDelFlag, DelFlagEnum.DEL_FALSE.key())).eq(MenuRecipe::getStallId, content.getStallId()));
//   }
//
//   public PageVO<AndroidRecipeTypeDetailVO> getAllDishesByPage(PageDTO content) {
//      PageHelper.startPage(content.getPageNum(), content.getPageSize());
//      List<AndroidRecipeTypeDetailVO> productionMachineRecipe = this.menuRecipeService.getProductionMachineRecipe();
//      return PageVO.of(productionMachineRecipe);
//   }
}
