package com.bonus.canteen.core.order.module;

import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.cook.dto.AllocRecipeStallDTO;
import com.bonus.canteen.core.cook.dto.CookH5ReserveRecipeDTO;
import com.bonus.canteen.core.cook.dto.CookRecipeDTO;
import com.bonus.canteen.core.cook.service.ICookH5Service;
import com.bonus.canteen.core.cook.service.ICookRecipeService;
import com.bonus.canteen.core.cook.vo.*;
import com.bonus.canteen.core.order.domain.CookDishCheckDTO;
import com.bonus.common.core.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.*;

@Component
public class MenuModule {
    @Autowired
    private ICookRecipeService cookRecipeService;

    public AllocRecipeStallVO getMenuRecipeDish(CookDishCheckDTO cookDishCheckDTO) {
        AllocRecipeStallDTO allocRecipeStallDTO = new AllocRecipeStallDTO();
        allocRecipeStallDTO.setApplyDate(cookDishCheckDTO.getApplyDate());
        allocRecipeStallDTO.setCanteenId(cookDishCheckDTO.getCanteenId());
        allocRecipeStallDTO.setStallId(cookDishCheckDTO.getStallId());
        allocRecipeStallDTO.setKey(cookDishCheckDTO.getApplyType());
        Map<Integer, List<CookH5ReserveRecipeDishesVO>> mealTimeTypeMap = new HashMap<>();
        List<AllocRecipeStallVO> cookRecipeList = cookRecipeService.selectCookRecipeList4Current(allocRecipeStallDTO);
        if (CollUtil.isNotEmpty(cookRecipeList) && cookRecipeList.size() == 1) {
            return cookRecipeList.get(0);
        }else {
            throw new ServiceException("菜谱信息异常");
        }
    }
}
