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

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.auth.config.LeNiuDataPermission;
import com.bonus.canteen.core.auth.enums.DataPermissionTypeEnum;
import com.bonus.canteen.core.auth.po.MgrUserAuthPO;
import com.bonus.canteen.core.customer.model.CustInfo;
import com.bonus.canteen.core.marketing.vo.MktEffectiveUserVO;
import com.bonus.canteen.core.menu.dto.MenuRecipeV2PageDTO;
import com.bonus.canteen.core.menu.entity.MenuRecipe;
import com.bonus.canteen.core.menu.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

@Mapper
public interface MenuRecipeMapper extends BaseMapper<MenuRecipe> {

   CustInfo selectOrgAndPsnByCustLimitId(CustInfo custInfo);
   List<MktEffectiveUserVO> selectAllUserEff(@Param("effType") Integer effType, @Param("delFlag") Integer delFlag);

   List<AppletWeekRecipeVO> selectWeekRecipe(@Param("applyDate") LocalDate applyDate, @Param("recipeId") Long recipeId, @Param("recipeIdList") List<Long> recipeIdList);

   List<AppletRecommendDishesVO> selectAllRecipeDishesList(@Param("recipeId") Long recipeId, @Param("mealtimeType") Integer mealtimeType);

   List<AppletReserveRecipeVO> selectReserveRecipe(@Param("applyDate") LocalDate applyDate, @Param("recipeId") Long recipeId);

   @Select({"select stall_id from menu_recipe ${ew.customSqlSegment}"})
   Long selectStallIdByWrappers(@Param("ew") Wrapper<MenuRecipe> wrapper);

   @Select({"select mr.stall_id from menu_recipe mr left join menu_recipe_detail mrd on mr.recipe_id = mrd.recipe_id where mrd.detail_id = #{detailId}"})
   Long selectShopstallIdByDetailId(Long detailId);

   @Select({"select recipe_id, recipe_name from menu_recipe ${ew.customSqlSegment}"})
   List<MenuRecipe> selectRecipeNameMap(@Param("ew") Wrapper<MenuRecipe> wrapper);

   @LeNiuDataPermission(
           alias = "aa",
           permissionType = DataPermissionTypeEnum.PERMISSION_AREA
   )
   Page<MenuRecipeV2PageVO> selectAllRecipeV2List(Page<MenuRecipeV2PageVO> page, @Param("content") MenuRecipeV2PageDTO content, @Param("delFlag") Integer delFlag, @Param("authPO") MgrUserAuthPO authPO);

   List<AndroidRecipeDetailVO> selectAndroidRecipeTwo(@Param("recipeId") Long recipeId, @Param("applyDate") LocalDate applyDate);

   List<MenuEleDishRowRecipeVO> selectEleDishRowRecipe(@Param("recipeId") Long recipeId, @Param("applyDate") LocalDate applyDate);

   List<PersonalDietRecordVO> selectOrdDetailByCustId(@Param("custId") Long custId, @Param("startTime") LocalDate startTime, @Param("endTime") LocalDate endTime, @Param("ordStateList") List<Integer> ordStateList);

   List<AndroidAllProductsRecipeVO> selectAndroidRecipeDetail(@Param("applyDate") LocalDate applyDate, @Param("mealtimeType") Integer mealtimeType, @Param("recipeIdList") List<Long> recipeIdList, @Param("delFlag") Integer delFlag);

   List<AndroidRecipeDetailThreeVO> selectAndroidRecipeThree(@Param("recipeIdList") List<Long> recipeIdList, @Param("effIdSet") Set<Long> effIdSet, @Param("applyDate") LocalDate applyDate);

   AppletMenuRecipeCanteenVO getRecipeInfoByRecipeId(@Param("recipeId") Long recipeId);

   List<AndroidGetRecipeDishesVO> selectAndroidRecipeDetailByRecipeId(@Param("applyDate") LocalDate applyDate, @Param("recipeId") Long recipeId);

   @Select({"select recipe_id, recipe_name from menu_recipe ${ew.customSqlSegment}"})
   List<AndroidGetRecipeByShopVO> selectRecipeListByShop(@Param("ew") Wrapper<MenuRecipe> wrapper);
}
