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

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

import java.util.*;

/**
 * EncipherTypeEnum
 *
 * @author fengxiang.zhang
 * @since 1.0
 */
public enum DecipherTypeEnum implements EnumClass {

    base64("Base64解密", "base64"),
    sm4("国密SM4解密", "sm4"),
    ;

    public String key;
    public String value;

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

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

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