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

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bonus.canteen.core.device.domain.DeviceInfo;
import com.bonus.canteen.core.device.domain.DeviceInfo;
import com.bonus.canteen.core.menu.domain.MenuAppRecipe;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bonus.canteen.core.alloc.domain.AllocCanteen;
import com.bonus.canteen.core.alloc.domain.AllocStall;
import com.bonus.canteen.core.menu.domain.MenuAppRecipe;
import com.bonus.canteen.core.menu.domain.MenuRecipe;
import com.bonus.canteen.core.menu.domain.MenuRecipeDetail;
import com.bonus.canteen.core.menu.domain.MenuRecipeDishes;
import com.bonus.canteen.core.menu.domain.*;
import com.bonus.canteen.core.menu.dto.*;
import com.bonus.canteen.core.menu.model.DeviceRecipe;
import com.bonus.canteen.core.menu.vo.*;
import com.bonus.canteen.core.menu.dto.MenuRecipeParamDTO;
import com.bonus.canteen.core.menu.dto.RecipeDishesCountDTO;
import com.bonus.canteen.core.menu.model.MenuBaseModel;
import com.bonus.canteen.core.menu.vo.MenuRecipeDataVO;
import com.bonus.canteen.core.menu.vo.MenuRecipeDetailDateVO;
import com.bonus.canteen.core.menu.vo.MenuRecipeV2VO;
import org.apache.ibatis.annotations.*;
import com.bonus.canteen.core.menu.model.MenuDishesCostModel;
import com.bonus.canteen.core.menu.vo.*;
import org.springframework.beans.PropertyValues;

/**
 * 菜品计划信息Mapper接口
 *
 * @author xsheng
 * @date 2025-04-03
 */
public interface MenuRecipeMapper extends BaseMapper<MenuRecipe> {
    /**
     * 查询菜品计划信息
     *
     * @param id 菜品计划信息主键
     * @return 菜品计划信息
     */
    public MenuRecipe selectMenuRecipeById(Long id);

    /**
     * 查询菜品计划信息列表
     *
     * @param menuRecipe 菜品计划信息
     * @return 菜品计划信息集合
     */
    public List<MenuRecipeVO> selectMenuRecipeList(MenuRecipe menuRecipe);
    public List<AllocRecipeStallVO> selectMenuRecipeListV2(AllocRecipeStallDTO menuRecipe);

    List<StallAndRecipeBindDto> selectRecipeByStallIdsAndBindType(@Param("stallIds") List<Long> stallIds, @Param("bindType") Integer bindType);

    List<MenuRecipeDateVO> selectTmpBetweenDateDetailList(@Param("recipeIds") List<Long> recipeIds, @Param("applyStartDate") LocalDate applyStartDate, @Param("applyEndDate") LocalDate applyEndDate);

    List<MenuRecipeDishesVO>getDishesListByDetailId(String detailsId);

    List<MenuRecipeMealtimeTypeVO> getDishesListByRecipeId(@Param("recipeId") String recipeId,@Param("applyDate") String applyDate);

    /**
     * 新增菜品计划信息
     *
     * @param menuRecipe 菜品计划信息
     * @return 结果
     */
    public int insertMenuRecipe(MenuRecipe menuRecipe);

    /**
     * 修改菜品计划信息
     *
     * @param menuRecipe 菜品计划信息
     * @return 结果
     */
    public int updateMenuRecipe(MenuRecipe menuRecipe);

    /**
     * 删除菜品计划信息
     *
     * @param id 菜品计划信息主键
     * @return 结果
     */
    public int deleteMenuRecipeById(Long id);

    /**
     * 批量删除菜品计划信息
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteMenuRecipeByIds(Long[] ids);

    /**
     * 获取菜品列表
     *
     * @param dto
     * @return
     */
    List<MenuRecipeV2VO> getDishesList(MenuRecipeParamDTO dto);

    /**
     * 根据recipeIds获取菜品数量
     *
     * @param recipeIds
     * @return
     */
    List<RecipeDishesCountDTO> getDishesCountByRecipeIds(@Param("recipeIds") List<Long> recipeIds);

    List<MenuRecipeDetail> getMenuDishDeatilList(@Param("recipeIds") List<Long> recipeIds);

    /**
     * 根据recipeIds获取日期
     *
     * @param recipeIds
     * @return
     */
    List<MenuRecipeDataVO> selectApplyDateListByRecipeId(@Param("applyDate") LocalDate applyDate, @Param("recipeIds") List<Long> recipeIds);

    /**
     * 查询基础
     *
     * @param baseDishesIdList
     * @return
     */
    List<MenuBaseModel> selectBaseSizeDishesId(@Param("baseDishesIdList") List<Long> baseDishesIdList);

    MenuRecipe selectMenuRecipe(Long recipeId);

    AllocCanteen getCanNum(Long canteenId);

    AllocStall getStallNum(Long stallId);

    boolean exists(MenuAppRecipe appRecipe);

    List<Long> selectRecipeInSameShop(@Param("stallId") Long stallId, @Param("effId") Long effId, @Param("bindType") Integer bindType, @Param("mealLineId") Long mealLineId);

    void delete(MenuAppRecipe appRecipe);

    int insert(MenuAppRecipe appRecipe);

    Long selectCount(MenuRecipeAddDTO dto);

    void insertData(MenuRecipe recipe);

    MenuRecipe getOneById(Long recipeId);

    List<Long> selectDetailIds(@Param("dto") GetRecipeDTO dto, @Param("mealType") Integer mealType);

    List<MenuRecipeDetail> selectDetailsList(
            @Param("dto") GetRecipeDTO dto,
            @Param("currentDate") LocalDate currentDate,
            @Param("mealType") Integer mealType
    );

    List<MenuRecipeDishes> getMenuRecipeDishesList(@Param("haveDetailIds") List<Long> haveDetailIds);

    List<MenuRecipeDetail> selectMenuRecipeDetail(@Param("bean") MenuRecipeDetail menuRecipeDetailBean,@Param("weeks") List<Integer> weeks);

    List<Long> selectDetailIdListByWrapper(
            @Param("recipeId") Long recipeId,
            @Param("applyDateList") List<LocalDate> applyDateList,
            @Param("isComplete") Boolean isComplete,
            @Param("recipeDateList") List<MenuRecipeDateAddDTO> recipeDateList
    );

    List<MenuRecipeDishes> selectBatchIds(@Param("ids") List<Long> ids);

    void deleteMenuRecipeDetailByIds(@Param("list") List<Long> detailIds);

    void deleteMenuRecipeDishesByIds(@Param("list") List<Long> detailIds);

    void insertMenuDetails(@Param("menuDetails") List<MenuRecipeDetail> recipeDetailV2List);

    void insertMenuDishes(@Param("menuDishes") List<MenuRecipeDishes> recipeDishesV2List);

    List<MenuAppRecipe> selectAppRecipeList(Long recipeId);

    void updateMenuRecipeDetail(@Param("recipeId") Long recipeId,@Param("time") LocalDateTime now);

    List<MenuRecipeDetailDateVO> getDetail(@Param("params") MenuRecipeParamDTO dto);

    Integer getRecipeBindCount(Long recipeId);

    List<Long> getDetailIdList(Long recipeId);

    int selectMenuAppRecipeCount(Long recipeId);

    List<MenuAllTypeDishesVO> selectTypeDishesList(MenuTypeDishesDTO dto);

    @Select({"select base_dishes_id, material_cost from menu_dishes ${ew.customSqlSegment}"})
    List<MenuDishesCostModel> selectMaterialCostList(@Param("ew") Wrapper<MenuDishes> wrapper);
    @Select({"select type_id, type_name, area_id from menu_dishes_type ${ew.customSqlSegment}"})
    List<MenuDishesTypeAllVO> getAllDishCategories(@Param("ew") Wrapper<MenuDishesType> wrapper);

    List<MenuRecipeDetailDateVO> selectDateDetailList(@Param("recipeId") Long recipeId, @Param("applyDate") LocalDate applyDate);
    @Select({"select * from menu_recipe_detail ${ew.customSqlSegment}"})
    List<MenuRecipeDetail> selectMenuRecipeDetailList(@Param("ew") Wrapper<MenuRecipeDetail> wrapper);
    @Select({"select * from menu_recipe_dishes ${ew.customSqlSegment}"})
    List<MenuRecipeDishes> selectMenuRecipeDishList(@Param("ew") Wrapper<MenuRecipeDishes> wrapper);

    List<String> getSnByCanteenId(Long canteenId);

    int deleteRecipeByrecipeId(Long recipeId);

    List<Integer> getDeviceIdByDevivce(@Param("canteenId")String canteenId, @Param("stallId")String stallId);
    void updateRecipeByCanteeStallMeal(@Param("recipeId")String recipeId, @Param("canteenId")String canteenId, @Param("stallId")String stallId, @Param("deviceIds")List<Integer> deviceIds);
    Long getRecipeIdBySn(String machineSn);

    List<MenuAndroidRecipeDetailVO> selectMenuRecipeDetailLists(Long recipeId);

    List<IssueRecipeDetailCompressVO> selectRecipeDishList(@Param("detailIds") List<Long> detailIds);

    List<IssueRecipeMealCompressVO> getMenuRecipeListByDishesIds(@Param("dishesIds") List<Long> dishesIds);

    List<MealTimeVO> getMealTimeList(Long stallId);

    List<DeviceMealtimeVO> getBasicsTimeIntervals(Long stallId);


    List<MenuRecipeDetail> MenuRecipeDetailList(Long recipeId);


    List<MenuRecipeV2PageVO> getMenuRecipeList(MenuRecipeV2PageDTO dto);

    List<String> selectDishesNameAndCanteenName();

 //   @Select("select material_name as materialName,material_id as materialId from menu_material")
   // @Results({ @Result(property = "key", column = "materialName"), @Result(property = "value", column = "materialId")})
    List<MapBean> getMenuMaterialMap();

   // @Results({ @Result(property = "key", column = "typeName"), @Result(property = "value", column = "typeId")})
    List<MapBean> getMenuMaterialTypeMap();

    @Select({"select type_id from menu_dishes_type where default_flag = #{defaultFlag}"})
    Long selectDefaultTypeId(Integer key);

    void insertMenuDishesType(MenuDishesType dishesType);

    List<MapBean> getDishesCookMap();

    int insertMenuMateralDishes(@Param("materialList") ArrayList<MenuMaterialDishes> menuMaterialDishesList);

    MenuNutritionDetailVO getMenuNutritionDetailById(Long nutritionId);

    @Select({"select recipe_id as recipeId from menu_recipe   ${ew.customSqlSegment}"})
    List<Long> selectRecipeIdList(@Param("ew")  QueryWrapper<MenuRecipe> recipeType);


    List<String> getDeviceSnByIds(@Param("list") List<Integer> deviceInfoList);
}
