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 EncipherTypeEnum implements EnumClass {

    base64("Base64加密", "base64"),
    md5("MD5加密", "md5"),
    crc32("CRC32加密", "crc32"),
    sha("SHA加密", "sha"),
    sha224("SHA-224加密", "sha224"),
    sha256("SHA-256加密", "sha256"),
    sha384("SHA-384加密", "sha384"),
    sha512("SHA-512加密", "sha512"),
    sm4("国密SM4加密", "sm4"),
    ;

    public String key;
    public String value;

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

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

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