package com.ycwl.basic.enums;

import lombok.Getter;

/**
 * 视频评价来源枚举
 */
@Getter
public enum VideoReviewSourceEnum {

    /**
     * 订单
     */
    ORDER("ORDER", "订单"),

    /**
     * 渲染
     */
    RENDER("RENDER", "渲染");

    /**
     * 枚举代码
     */
    private final String code;

    /**
     * 枚举描述
     */
    private final String description;

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

    /**
     * 根据code获取枚举
     *
     * @param code 枚举代码
     * @return 枚举对象,不存在则返回null
     */
    public static VideoReviewSourceEnum fromCode(String code) {
        if (code == null || code.isEmpty()) {
            return null;
        }
        for (VideoReviewSourceEnum value : VideoReviewSourceEnum.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 验证code是否有效
     *
     * @param code 枚举代码
     * @return true-有效, false-无效
     */
    public static boolean isValid(String code) {
        return fromCode(code) != null;
    }
}
