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

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.common.utils.BaseTreeNode;
import com.bonus.canteen.core.drp.po.CategoryMaterialNumModel;
import com.bonus.canteen.core.menu.dto.CategoryTreeListDTO;
import com.bonus.canteen.core.menu.entity.MenuMaterialCategory;
import com.bonus.canteen.core.menu.po.MenuMaterialCategoryModel;
import com.bonus.canteen.core.menu.vo.MenuCategoryChild;
import com.bonus.canteen.core.menu.vo.MenuCategoryTreeVO;
import com.bonus.canteen.core.menu.vo.MenuMaterialCategoryPageVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MenuMaterialCategoryMapper extends BaseMapper<MenuMaterialCategory> {
   @Select({"select category_id from menu_material_category ${ew.customSqlSegment}"})
   Long selectCategoryIdByWrapper(@Param("ew") Wrapper<MenuMaterialCategory> wrapper);

   @Select({"select category_id,category_num,category_name,category_type, crby, crtime, upby, uptime from menu_material_category ${ew.customSqlSegment}"})
   Page<MenuMaterialCategoryPageVO> selectAllList(Page<MenuMaterialCategoryPageVO> page, @Param("ew") Wrapper<MenuMaterialCategory> wrapper);

   @Select({"select category_id childId, category_name childName, parent_id from menu_material_category ${ew.customSqlSegment}"})
   List<MenuCategoryChild> selectByParentId(@Param("ew") Wrapper<MenuMaterialCategory> wrapper);

   @Select({"select category_id id, parent_id, category_name,category_type,area_id from menu_material_category ${ew.customSqlSegment}"})
   List<MenuCategoryTreeVO> selectCategoryTree(@Param("ew") LambdaQueryWrapper<MenuMaterialCategory> lambdaQueryWrapper);

   @Select({"select category_id from menu_material_category where parent_id = #{categoryId}"})
   List<Long> selectChildId(Long categoryId);

//   @Select({"select category_id, category_name from menu_material_category ${ew.customSqlSegment}"})
//   List<MenuMaterialCategoryIdNameVO> selectCategoryIdAndNameListByWrapper(@Param("ew") Wrapper<MenuMaterialCategory> wrapper);

   @Select({"select category_id from menu_material_category where parent_id = -1 and category_type = #{categoryType} and del_flag = 2"})
   Long selectIdByType(@Param("categoryType") Integer categoryType);

//   @Select({"select category_id,category_name from menu_material_category where category_type = #{categoryType} and del_flag = #{delFlag}"})
//   List<ProductCategoryListVO> listProductCategory(@Param("categoryType") Integer categoryType, @Param("delFlag") Integer delFlag);

//   List<AndroidCategoryVO> listCategoryByParentId(@Param("content") CategoryTreeListDTO content, @Param("delFlag") Integer delFlag);

   @Select({"select MAX(category_num) from menu_material_category where parent_id = #{parentId} and category_type = #{categoryType} and del_flag = #{delFlag}"})
   String getCategoryChildMaxNum(@Param("parentId") Long parentId, @Param("categoryType") Integer categoryType, @Param("delFlag") Integer delFlag);
//
   @Select({"select category_id,category_num,category_name,parent_id,category_type from menu_material_category where category_id = #{categoryId}"})
   MenuMaterialCategoryModel getCategoryInfoById(@Param("categoryId") Long categoryId);

//   List<CategoryMaterialNumModel> listAllOneLevelCategory(@Param("delFlag") Integer delFlag);

//   List<AndroidCategoryVO> selectNameListByIdList(@Param("categoryIds") List<Long> categoryIds);

//   List<BaseTreeNode> listIdAndParentId();
}
