package com.iwunu.nbiot.lock.service.impl;

import com.iwunu.nbiot.lock.entity.IotDictionaries;
import com.iwunu.nbiot.lock.repository.IotDictionariesRepository;
import com.iwunu.nbiot.lock.service.IotDictionariesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author kinfeng
 * @date 2022/4/19 2:59 PM
 * @desc
 */
@Service
public class IotDictionariesServiceImpl implements IotDictionariesService  {

    @Autowired
    private IotDictionariesRepository iotDictionariesRepository;


    @Override
    public List<IotDictionaries> findListByType(String type) {
        return iotDictionariesRepository.findListByType(type);
    }

    @Override
    public Map<String,String> listToMapString(List<IotDictionaries> list) {
        return list.stream().collect(Collectors.toMap(IotDictionaries::getName, IotDictionaries::getValue));
    }

    @Override
    public Map<String, Integer> listToMapInteger(List<IotDictionaries> list) {
        Map<String,Integer> map = new HashMap<>() ;
        for(IotDictionaries iotDictionaries:list){
            map.put(iotDictionaries.getName(),Integer.valueOf(iotDictionaries.getValue()));
        }
        return map ;

    }

	@Override
	public Map<String, String> listToMapValueString(List<IotDictionaries> list) {
		return list.stream().distinct().collect(Collectors.toMap(IotDictionaries::getValue,IotDictionaries::getName));
	}


}
