package net.northking.cctp.element.string.enums;

import com.alibaba.fastjson.JSON;
import net.northking.cctp.element.core.type.EnumClass;

import java.util.*;

/**
 * TypeConversionEnum
 *
 * @author fengxiang.zhang
 * @since 1.0
 */
public enum TypeConversionContainEnum implements EnumClass {
    isContain("是否包含", "0"),
    isPrefix("是否前缀", "1"),
    isSuffix("是否后缀", "2"),
    ;

    private String key;
    private String value;

    TypeConversionContainEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public static TypeConversionContainEnum from(String value) {
        for (TypeConversionContainEnum item : TypeConversionContainEnum.values()) {
            if (item.value.equals(value)) {
                return item;
            }
        }
        throw new IllegalArgumentException("未知的转换类型:" + value);
    }

    @Override
    public String getEnumData() {
        List<Map<String, Object>> result = new ArrayList<>();
        for (TypeConversionContainEnum item : EnumSet.allOf(TypeConversionContainEnum.class)) {
            Map<String, Object> one = new HashMap(1);
            one.put("label", item.key);
            one.put("value", item.value);
            result.add(one);
        }
        return JSON.toJSONString(result);
    }
}
