package com.ruoyi.framework.converter;

import com.ruoyi.project.system.enums.BaseEnum;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
import springfox.documentation.schema.Maps;

import java.util.HashMap;
import java.util.Map;

public class IntegerToEnumConverterFactory implements ConverterFactory<String, BaseEnum> {

    @SuppressWarnings("rawtypes")
    private static final Map<Class, Converter> CONVERTERS = new HashMap<>();

    @Override
    public <T extends BaseEnum> Converter<String, T> getConverter(Class<T> targetType) {
        Converter<String, T> converter = CONVERTERS.get(targetType);
        if (converter == null) {
            converter = new IntegerToEnumConverter(targetType);
            CONVERTERS.put(targetType, converter);
        }
        return converter;
    }

}
