package com.sunyard.chsm.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

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

/**
 * @author liulu
 * @since 2024/10/23
 */
@Getter
@AllArgsConstructor
public enum KeyStatus {

    WAIT_ENABLED("wait_enabled", "待生效"),
    ENABLED("enabled", "已启用"),
    DISABLED("disabled", "已停用"),
    ARCHIVED("archived", "已归档"),
    EXPIRED("expired", "已过期"),
    DESTROY("destroy", "已销毁"),
    ;
    private final String code;
    private final String desc;

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

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

}
