package com.sjyt.icom.asst.common.enums;

import cn.hutool.core.util.ObjectUtil;
import com.sjyt.icom.asst.common.exception.CmdCategoryException;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * <p>Srs回调事件枚举</p>
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/6/17 17:13
 */
@Getter
@AllArgsConstructor
public enum SrsCallBackEnum {
    /**
     * 连接
     */
    CONNECT(1, "on_connect"),
    /**
     * 关闭
     */
    CLOSE(2, "on_close"),
    /**
     * 推流
     */
    PUBLISH(3, "on_publish"),
    /**
     * 停止推流
     */
    UN_PUBLISH(4, "on_unpblish"),
    /**
     * 拉流
     */
    PLAY(5, "on_play"),
    /**
     * 停止拉流
     */
    STOP(6, "on_stop"),
    /**
     * 录制关闭
     */
    DVR(7, "on_dvr"),
    /**
     * hls
     */
    hls(8, "on_hls"),
    /**
     * hls_notify
     */
    HLS_NOTIFY(9, "on_hls_notify");

    final int code;
    final String action;

    public static SrsCallBackEnum of(String code) {
        SrsCallBackEnum[] values = SrsCallBackEnum.values();
        for (SrsCallBackEnum value : values) {
            if (ObjectUtil.equals(code, value.code)) {
                return value;
            }
        }
        throw new CmdCategoryException("callback类型异常");
    }
}
