package com.ycwl.basic.enums;

/**
 * 人脸对应模板渲染状态枚举
 */
public enum TemplateRenderStatus {

    NONE(0, "没有渲染"),
    /**
     * 正在渲染中
     */
    RENDERING(1, "正在渲染中"),

    /**
     * 已渲染完成
     */
    RENDERED(2, "已渲染完成");

    private final int code;
    private final String description;

    TemplateRenderStatus(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据code获取枚举
     */
    public static TemplateRenderStatus fromCode(int code) {
        for (TemplateRenderStatus status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown TemplateRenderStatus code: " + code);
    }

    /**
     * 根据code获取枚举，如果不存在则返回默认值
     * @param code 状态码
     * @param defaultStatus 默认状态
     * @return 枚举值
     */
    public static TemplateRenderStatus fromCodeOrDefault(int code, TemplateRenderStatus defaultStatus) {
        for (TemplateRenderStatus status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        return defaultStatus;
    }

    /**
     * 判断是否已完成渲染
     */
    public boolean isRendered() {
        return this == RENDERED;
    }

    /**
     * 判断是否正在渲染
     */
    public boolean isRendering() {
        return this == RENDERING;
    }
}
