package org.qinan.safetyeval.domain.constant;

/**
 * 备案状态（全模块统一五态）
 */
public enum QualFilingStatusEnum {

    FILED(1, "已备案"),
    REVIEWING(2, "审核中"),
    REJECTED(3, "已打回"),
    CHANGE_REVIEWING(4, "变更审核中"),
    DRAFT(5, "暂存");

    private final int code;
    private final String name;

    QualFilingStatusEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static QualFilingStatusEnum ofCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (QualFilingStatusEnum item : values()) {
            if (item.code == code) {
                return item;
            }
        }
        return null;
    }

    /** 表单可编辑：暂存、已打回 */
    public static boolean isEditable(Integer code) {
        return code != null && (code == DRAFT.code || code == REJECTED.code);
    }

    /** 已备案稳定态，可发起变更 */
    public static boolean isFiled(Integer code) {
        return code != null && code == FILED.code;
    }
}
