package com.ningdatech.pmapi.meta.helper.impl;

import com.ningdatech.pmapi.meta.constant.DictAllTypeEnum;
import com.ningdatech.pmapi.meta.helper.basic.AbstractDictionaryCache;
import com.ningdatech.pmapi.meta.model.dto.DictionaryDTO;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * @author liuxinxin
 * @date 2022/7/22 上午10:47
 */
@Component
public class DictionaryCacheImpl extends AbstractDictionaryCache {

    @Override
    public List<DictionaryDTO> getDictionaryListByDictionaryType(DictAllTypeEnum dictionaryType) {
        return dictionaryCacheHelper.get(dictionaryType.getKey());
    }

    @Override
    public List<DictionaryDTO> getDictionaryListByDictionaryType(String dictionaryType) {
        return dictionaryCacheHelper.get(dictionaryType);
    }

    @Override
    public DictionaryDTO getDictionaryByDictionaryType(DictAllTypeEnum dictionaryType, String code) {
        return Objects.requireNonNull(dictionaryCacheHelper.get(dictionaryType.getKey()))
                .stream().filter(w -> w.getDictionaryCode().equals(code))
                .findFirst().orElse(null);
    }

    @Override
    public DictionaryDTO getByCode(String dictionaryCode) {
        return dictionaryMap.get(dictionaryCode);
    }

}
