package com.ycwl.basic.enums;

/**
 * 人脸片段更新状态枚举
 * 用于标记人脸对应的视频片段是否有新增更新
 */
public enum FacePieceUpdateStatus {

    /**
     * 有新片段
     * Redis键不存在时的默认状态，代表有新的视频片段产生
     */
    HAS_NEW_PIECES(0, "有新片段"),

    /**
     * 无新片段
     * Redis键存在时的状态，代表当前没有新的视频片段
     */
    NO_NEW_PIECES(1, "无新片段");

    private final int code;
    private final String description;

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

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

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

    /**
     * 根据Redis键是否存在判断状态
     * @param keyExists Redis键是否存在
     * @return 键存在返回NO_NEW_PIECES，键不存在返回HAS_NEW_PIECES
     */
    public static FacePieceUpdateStatus fromKeyExists(boolean keyExists) {
        return keyExists ? NO_NEW_PIECES : HAS_NEW_PIECES;
    }

    /**
     * 判断是否有新片段
     */
    public boolean hasNewPieces() {
        return this == HAS_NEW_PIECES;
    }
}
