package com.sunyard.chsm.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author liulu
 * @since 2024/10/16
 */
@Getter
@AllArgsConstructor
public enum ApiGroupEnum {

    KEY_MANAGE_API("key_manage_api", "密钥管理接口"),
    SYM_API("sym_api", "对称密钥计算接口"),
    ASYM_API("asym_api", "非对称密钥计算接口"),
    HASH_API("hash_api", "杂凑计算接口"),
    CERT_API("cert_api", "证书接口"),
    ;

    private final String code;
    private final String name;

    public static ApiGroupEnum of(String code) {
        if (code == null || code.trim().isEmpty()) {
            return null;
        }

        return Arrays.stream(ApiGroupEnum.values())
                .filter(it -> Objects.equals(it.code, code))
                .findFirst()
                .orElse(null);
    }
}
