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

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bonus.canteen.core.menu.dto.ExistDateDto;
import com.bonus.canteen.core.menu.dto.RecipeDishesCountDto;
import com.bonus.canteen.core.menu.entity.MenuRecipeDetail;
import com.bonus.canteen.core.menu.entity.MenuRecipeDishes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.Collection;
import java.util.List;

@Mapper
public interface MenuRecipeDishesMapper extends BaseMapper<MenuRecipeDishes> {
   Integer insertValues(Collection<MenuRecipeDishes> list);

   @Update({"update menu_recipe_dishes set sale_num = sale_num + #{saleNum}, surplus_num = surplus_num - #{saleNum} where id = #{id}"})
   void updateNumById(@Param("id") Long id, @Param("saleNum") Integer saleNum);

   Integer selectExistLeftJoinByDishesId(@Param("dishesIdList") List<Long> dishesIdList);

   List<ExistDateDto> queryDishesByDate(@Param("dates") List<LocalDate> dates, @Param("recipeId") Long recipeId, @Param("dishesId") Long dishesId);

   List<RecipeDishesCountDto> getDishesCountByRecipeIds(@Param("recipeIds") List<Long> recipeIds);

   @Select({"select detail_id, mealtime_type from menu_recipe_detail ${ew.customSqlSegment}"})
   List<MenuRecipeDetail> selectSourceDetailByWrapper(@Param("ew") Wrapper<MenuRecipeDetail> wrapper);

   @Select({"select dishes_id, price, supply_num, restrict_num, sale_price from menu_recipe_dishes ${ew.customSqlSegment}"})
   List<MenuRecipeDishes> selectSourceDishesByWrapper(@Param("ew") Wrapper<MenuRecipeDishes> wrapper);

   @Select({"select distinct dishes_id from menu_recipe_dishes ${ew.customSqlSegment}"})
   List<Long> selectDishesIdListByWrapper(@Param("ew") Wrapper<MenuRecipeDishes> wrapper);

}
