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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.menu.entity.MenuMealtimeTypeDishes;
import com.bonus.canteen.core.menu.mapper.MenuMealtimeTypeDishesMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MenuMealtimeTypeDishesService extends ServiceImpl<MenuMealtimeTypeDishesMapper, MenuMealtimeTypeDishes> {
   public void insertBatch(List<Integer> mealtimeTypes, Long dishesId) {
      List<MenuMealtimeTypeDishes> data = mealtimeTypes.stream().map((season) -> {
         return (new MenuMealtimeTypeDishes()).setDishesId(dishesId).setMealtimeType(season);
      }).collect(Collectors.toList());
      this.saveBatch(data);
   }

   public List<Integer> selectSeasonByDishesId(Long dishesId) {
      return this.listObjs(Wrappers.lambdaQuery(MenuMealtimeTypeDishes.class)
              .eq(MenuMealtimeTypeDishes::getDishesId, dishesId)
              .eq(MenuMealtimeTypeDishes::getIfDel, 2)
              .select(MenuMealtimeTypeDishes::getMealtimeType), Object::toString)
              .stream().map(Integer::valueOf).collect(Collectors.toList());
   }

   public void deleteByDishesId(Long dishesId) {
      this.remove(Wrappers.lambdaQuery(MenuMealtimeTypeDishes.class)
              .eq(MenuMealtimeTypeDishes::getDishesId, dishesId));
   }
}
