package com.bonus.canteen.core.device.api;

import cn.hutool.core.util.ObjectUtil;
import com.bonus.canteen.core.device.manage.dto.DeviceDTO;
import com.bonus.canteen.core.device.manage.service.DeviceInfoService;
import com.bonus.canteen.core.device.manage.service.DeviceMetadataService;
import com.bonus.common.houqin.constant.LeConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class DeviceV2Api {
   private static final Logger log = LoggerFactory.getLogger(DeviceV2Api.class);

   @Autowired
   @Lazy
   private DeviceInfoService deviceInfoService;
   @Resource
   @Lazy
   private DeviceMetadataService deviceMetadataService;

//   public void insert(DeviceDTO dto) {
//      this.deviceInfoService.insert(dto);
//   }
//
//   public void update(DeviceDTO dto) {
//      this.deviceInfoService.update(dto);
//   }
//
//   public void delete(Long deviceId) {
//      this.deviceInfoService.delete(deviceId);
//   }

//
//   public DeviceInfoVO getDeviceInfoVoByNum(String deviceNum) {
//      return this.deviceInfoService.getDeviceInfoVoByNum(deviceNum);
//   }
//
//   public List<DeviceInfoVO> getDeviceInfoVoByNumList(List<String> deviceNumList) {
//      return this.deviceInfoService.getDeviceInfoVoByNumList(deviceNumList);
//   }
//
//   public DeviceInfoVO getDeviceInfoVoById(Long deviceId) {
//      return this.deviceInfoService.getDeviceInfoVoById(deviceId);
//   }
//
//   public List<DeviceInfoVO> getPrintDeviceInfoVoByCanteenandStallId(String canteenId, String stallId) {
//      List<DeviceInfoVO> deviceInfoVOList = this.deviceInfoService.listDeviceInfoVoByType(SourceTypeEnum.PRINTER.getKey());
//      List<DeviceInfoVO> deviceInfoVOS = (List)deviceInfoVOList.stream().filter((s) -> {
//         return ObjectUtil.isNotEmpty(s.getDeviceMetadata()) && ObjectUtil.equals(s.getDeviceMetadata().get("canteenId"), canteenId) && ObjectUtil.contains(s.getDeviceMetadata().get("stallId"), stallId) && ObjectUtil.equals(LeConstants.COMMON_YES, s.getIfEnable());
//      }).collect(Collectors.toList());
//      return ObjectUtil.isNotEmpty(deviceInfoVOS) ? deviceInfoVOS : (List)deviceInfoVOList.stream().filter((s) -> {
//         return ObjectUtil.isNotEmpty(s.getDeviceMetadata()) && ObjectUtil.equals(s.getDeviceMetadata().get("canteenId"), canteenId) && ObjectUtil.isEmpty(s.getDeviceMetadata().get("stallId")) && ObjectUtil.equals(LeConstants.COMMON_YES, s.getIfEnable());
//      }).collect(Collectors.toList());
//   }
//
//   public List<DeviceInfoVO> getPrintDeviceInfoVoBysupermarketIdId(String supermarketId) {
//      List<DeviceInfoVO> deviceInfoVOList = this.deviceInfoService.listDeviceInfoVoByType(SourceTypeEnum.PRINTER.getKey());
//      return (List)deviceInfoVOList.stream().filter((s) -> {
//         return ObjectUtil.isNotEmpty(s.getDeviceMetadata()) && ObjectUtil.equals(s.getDeviceMetadata().get("supermarketId"), supermarketId) && ObjectUtil.equals(LeConstants.COMMON_YES, s.getIfEnable());
//      }).collect(Collectors.toList());
//   }
//
//   public List<DeviceInfoVO> getPrintDeviceInfoVoByFlag(String flag) {
//      List<DeviceInfoVO> deviceInfoVOList = this.deviceInfoService.listDeviceInfoVoByType(SourceTypeEnum.PRINTER.getKey());
//      return (List)deviceInfoVOList.stream().filter((s) -> {
//         return ObjectUtil.isNotEmpty(s.getDeviceMetadata()) && ObjectUtil.equals(s.getDeviceMetadata().get(flag), String.valueOf(LeConstants.COMMON_YES)) && ObjectUtil.equals(LeConstants.COMMON_YES, s.getIfEnable());
//      }).collect(Collectors.toList());
//   }

   public Map<Integer, Integer> getDeviceTypeCountMap() {
      return this.deviceInfoService.getDeviceTypeCountMap();
   }
}
