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

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

import java.util.*;

/**
 * ModeTypeEnum
 *
 * @author fengxiang.zhang
 * @since 1.0
 */
public enum ParamsTypeEnum implements EnumClass {

    string("字符串", "1"),
    array("数组/集合", "2"),
    map("map集合", "3"),
    ;

    private String key;
    private String value;

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

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

    @Override
    public String getEnumData() {
        List<Map<String, Object>> result = new ArrayList<>();
        for (ParamsTypeEnum item : EnumSet.allOf(ParamsTypeEnum.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);
    }
}
