package com.bonus.canteen.core.menu.service.imlp;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.canteen.core.menu.dto.MenuCollectionDishesDTO;
import com.bonus.canteen.core.menu.dto.MenuDeleteDishesDTO;
import com.bonus.canteen.core.menu.entity.MenuCollectionDishes;
import com.bonus.canteen.core.menu.mapper.MenuCollectionDishesMapper;
import com.bonus.canteen.core.menu.service.CollectionDishesService;
import com.bonus.canteen.core.menu.vo.MenuCollectionDishesVO;
import com.bonus.common.houqin.i18n.I18n;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.invoke.SerializedLambda;
import java.util.List;

@Service
public class CollectionDishesServiceImpl extends ServiceImpl<MenuCollectionDishesMapper, MenuCollectionDishes> implements CollectionDishesService {
   private static final Logger log = LoggerFactory.getLogger(CollectionDishesServiceImpl.class);

   @Autowired
   private MenuCollectionDishesMapper  menuCollectionDishesMapper;

   @Override
   public void addDishes(MenuCollectionDishesDTO addDishesDto) {
      MenuCollectionDishes menuCollectionDishes = new MenuCollectionDishes();
      menuCollectionDishes.setDishesId(addDishesDto.getBaseDishesId());
      menuCollectionDishes.setCustId(addDishesDto.getCustId());
      menuCollectionDishes.setShopstallId(addDishesDto.getShopstallId());
      ((MenuCollectionDishesMapper)this.baseMapper).insert(menuCollectionDishes);
   }

   @Override
   public List<MenuCollectionDishesVO> queryDishesList(Long custId, MenuCollectionDishesDTO content) {
      if (!ObjectUtil.isNull(custId) && custId != -1L) {
        // content.setCustId(custId);
         return ((MenuCollectionDishesMapper)this.baseMapper).selectCollectionDishesListById(content);
      } else {
         throw new ServiceException(I18n.getMessage("menu_no_cust_info", new Object[0]));
      }
   }

   @Override
   public void deleteDishesById(MenuDeleteDishesDTO content) {
      ((MenuCollectionDishesMapper)this.baseMapper).delete((Wrapper)Wrappers.lambdaQuery(MenuCollectionDishes.class).in(MenuCollectionDishes::getDishesId, content.getDishesIdList()));
   }

   // $FF: synthetic method
//   private static Object $deserializeLambda$(SerializedLambda lambda) {
//      switch (lambda.getImplMethodName()) {
//         case "getDishesId":
//            if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("net/xnzn/core/menu/entity/MenuCollectionDishes") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
//               return MenuCollectionDishes::getDishesId;
//            }
//         default:
//            throw new IllegalArgumentException("Invalid lambda deserialization");
//      }
//   }
}
