package com.bonus.canteen.core.menuai.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.menu.mapper.MenuDishesAiConfigMapper;
import com.bonus.canteen.core.menuai.dto.MenuDishesAiConfigDTO;
import com.bonus.canteen.core.menuai.entity.MenuDishesAiConfig;
import com.bonus.canteen.core.menuai.service.MenuDishesAiConfigService;
import org.springframework.stereotype.Service;

@Service
public class MenuDishesAiConfigServiceImpl extends ServiceImpl<MenuDishesAiConfigMapper, MenuDishesAiConfig> implements MenuDishesAiConfigService {
//   public MenuDishesAiConfig getMenuDishesAiConfig(Long dishesId) {
//      MenuDishesAiConfig menuDishesAiConfig = (MenuDishesAiConfig)((MenuDishesAiConfigMapper)this.baseMapper).selectOne((Wrapper)Wrappers.lambdaQuery(MenuDishesAiConfig.class).eq(MenuDishesAiConfig::getDishesId, dishesId));
//      if (ObjectUtil.isNotEmpty(menuDishesAiConfig)) {
//         return menuDishesAiConfig;
//      } else {
//         MenuDishesAiConfig menuDishesAiConfig1 = new MenuDishesAiConfig();
//         menuDishesAiConfig1.setDishesId(dishesId);
//         menuDishesAiConfig1.setTrainCount(30);
//         menuDishesAiConfig1.setIdentifyCount(200);
//         return menuDishesAiConfig1;
//      }
//   }

    @Override
    public MenuDishesAiConfig updateMenuDishesAiConfig(MenuDishesAiConfigDTO menuDishesAiConfigDTO) {
        MenuDishesAiConfig menuDishesAiConfig = new MenuDishesAiConfig();
        BeanUtil.copyProperties(menuDishesAiConfigDTO, menuDishesAiConfig, new String[0]);
        Long dishesId = menuDishesAiConfig.getDishesId();
        MenuDishesAiConfig menuDishesAiConfig1 = this.baseMapper.selectOne(Wrappers.lambdaQuery(MenuDishesAiConfig.class)
                .eq(MenuDishesAiConfig::getDishesId, dishesId));
        if (ObjectUtil.isNotEmpty(menuDishesAiConfig1)) {
            menuDishesAiConfig.setId(menuDishesAiConfig1.getId());
            this.baseMapper.updateById(menuDishesAiConfig);
            return menuDishesAiConfig;
        } else {
            this.baseMapper.insert(menuDishesAiConfig);
            return menuDishesAiConfig;
        }
    }
}
