package com.platform.modules.live.constants;

import com.platform.common.utils.RedisKeys;
import com.platform.modules.live.utils.ReportTypeEnum;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by TROY on 2019/1/19.
 */
public class SceneConstants {

	// 直播状态
	public static Map<Integer, String> liveStates = null;
	// 预告
	public static final Integer LIVE_STATE_NOTICE = 0;
	// 正在直播
	public static final Integer LIVE_STATE_DIRECT = 1;
	// 回顾
	public static final Integer LIVE_STATE_REVIEW = 2;

	// 现场正在导播
	public static final Integer DIRECT_STATE_ON = 1;
	// 现场未在导播
	public static final Integer DIRECT_STATE_OFF = 0;
	/** 导播台默认appName*/
	public static String CASTER_APP_NAME = "caster";
	/** 导播台默认模板ids*/
	public static String CASTER_LIVETEMPLATEIDS = "liveTemplateIds_";
    /** 原画*/
    public static String TRANSCODECONFIG_ORIGINAL = "original";

	public enum PushEnum {

		NOT_START(0, "未开始"),
		PUSHING(1, "正在推流"),
		PAUSE(2, "暂停"),
		STOP(10, "停止");
		private Integer state;
		private String stateName;
		PushEnum(Integer state, String stateName) {
			this.state = state;
			this.stateName = stateName;
		}

		public Integer getState() {
			return state;
		}

		public String getStateName() {
			return stateName;
		}
	};
	// 现场状态
	// 草稿
	public static final Integer SCENE_DRAFT = 0;
	// 一审
	public static final Integer SCENE_ONE = 1;
	// 成品
	public static final Integer SCENE_PROD = 2;

	static {
		if(null==liveStates) {
			liveStates = new HashMap<>();
			liveStates.put(0, "预告");
			liveStates.put(1, "正在直播");
			liveStates.put(2, "回顾");
		}
	}

	/**
	 * 现场REDIS标识
	 */
	public static final String SCENE_REDIS_PREFIX = RedisKeys.getSceneKey();

	/**
	 * 直播导播台订阅地址
	 */
	public static final String LIVE_CASTER_SUB_URL = "/liveCaster";

    /**
     * 流类型
     */
	public enum InfoTypeEnum {

		REPORTER(1, "记者"),
		BROADCASTING_ROOM(2, "直播间"),
		THIRD (3, "第三方流");

		private Integer type;
		private String name;
		InfoTypeEnum(Integer type, String name) {
			this.type = type;
			this.name = name;
		}

		public static String getNameByType(Integer type) {
			for (InfoTypeEnum typeEnum : InfoTypeEnum.values()) {
				if (typeEnum.type == type) {
					return typeEnum.name;
				}
			}
			return null;
		}

		public static Integer getTypeByName(String name) {
			for (InfoTypeEnum typeEnum : InfoTypeEnum.values()) {
				if (typeEnum.name == name) {
					return typeEnum.type;
				}
			}
			return null;
		}
		public Integer getType() {
			return type;
		}

		public void setType(Integer type) {
			this.type = type;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}
	};
	/** 删除数据*/
	public static final Integer IS_DELETE = 1;
	/** 有效数据*/
	public static final Integer NOT_DELETE = 0;
	/** 回顾展示*/
	public static final Integer RECORD_SHOW = 1;
	/** 回顾待审核*/
	public static final Integer RECORD_TO_SHOW = 0;
	/** 是默认*/
	public static final Integer DEFAULT = 1;
	/** 不是默认*/
	public static final Integer NOT_DEFAULT = 0;
	/** 显示流*/
	public static final Integer STREAM_SHOW = 1;
	/** 不显示流*/
	public static final Integer STREAM_NOT_SHOW = 0;
	/** 转文字*/
	public static final Integer STREAM_TXT = 1;
	/** 不转文字*/
	public static final Integer STREAM_NOT_TXT = 0;
	/**
	 * 评论设置
	 */
	public enum AllowComment {
		/**
		 * 允许评论
		 */
		ALLOW_COMMENT(1, "允许评论"),
		/**
		 * 不允许评论
		 */
		NO_COMMENT(0, "不允许评论");

		private Integer value;
		private String desc;

		AllowComment(Integer value, String desc) {
			this.value = value;
			this.desc = desc;
		}

		public static String getDescByValue(Integer value) {
			if (null == value) {
				return null;
			}
			for (AllowComment object : AllowComment.values()) {
				if (object.getValue().equals(value)) {
					return object.getDesc();
				}
			}
			return null;
		}

		public Integer getValue() {
			return value;
		}

		public void setValue(Integer value) {
			this.value = value;
		}

		public String getDesc() {
			return desc;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}
	}

	/**
	 * 现场类型管理
	 */
	public enum SceneType {
		/** 现场类型 **/
		VIDEO(1, "视频现场", "video", true, Arrays.asList(ReportTypeEnum.AUDIO.getKey(), ReportTypeEnum.PICTURE.getKey())),
		AUDIO(2, "音频现场", "audio", true, ReportTypeEnum.getKeys()),
		IMAGE(3, "图片现场", "image", false, ReportTypeEnum.getKeys()),
		TEXT(4, "文字现场", "text", true, ReportTypeEnum.getKeys()),
		MERGE(5, "混合现场", "merge", true, ReportTypeEnum.getKeys()),
		SELECTION(6, "精品现场", "selection", true, ReportTypeEnum.getKeys()),
		// 20200511_Mxy VR现场
		VR(7, "VR现场", "vr", true, ReportTypeEnum.getKeys());

		private Integer key;
		private String name;
		private String path;
		private boolean allowLive;
		private List<Integer> reportTypes;

		SceneType(Integer key, String name, String path, boolean allowLive, List<Integer> reportTypes) {
			this.key = key;
			this.name = name;
			this.path = path;
			this.allowLive = allowLive;
			this.reportTypes = reportTypes;
		}

		/**
		 * 获取现场类型名称
		 * @param key 现场类型key
		 * @return
		 */
		public static String getNameByKey (Integer key) {
			if (null == key) {
				return null;
			}
			for (SceneType type : SceneType.values()) {
				if (type.key.equals(key)) {
					return type.getName();
				}
			}
			return null;
		}

		/**
		 * 获取现场路径
		 * @param key 现场类型key
		 * @return
		 */
		public static String getPathByKey (Integer key) {
			if (null == key) {
				return null;
			}
			for (SceneType type : SceneType.values()) {
				if (type.key.equals(key)) {
					return type.path;
				}
			}
			return null;
		}

		/**
		 * 现场类型是否允许直播
		 * @param key 现场类型key
		 * @return
		 */
		public static boolean isAllowLive(Integer key) {
			if (null == key) {
				return false;
			}
			for (SceneType type : SceneType.values()) {
				if (type.key.equals(key)) {
					return type.allowLive;
				}
			}
			return false;
		}

		public Integer getKey() {
			return key;
		}

		public void setKey(Integer key) {
			this.key = key;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getPath() {
			return path;
		}

		public void setPath(String path) {
			this.path = path;
		}
	}

	public static final String LIVENOTIFY_REQUESTMSG = "liveNotifyControllerNotifyMsg";

	/**
	 * 素材类型
	 */
	public enum MediaType {
		VIDEO(1, "视频"),
		AUDIO(2, "音频"),
		IMAGE(3, "图片");

		private Integer value;
		private String desc;

		MediaType(Integer value, String desc) {
			this.value = value;
			this.desc = desc;
		}

		public static String getDescByValue(Integer value) {
			if (null == value) {
				return null;
			}
			for (AllowComment object : AllowComment.values()) {
				if (object.getValue().equals(value)) {
					return object.getDesc();
				}
			}
			return null;
		}

		public Integer getValue() {
			return value;
		}

		public void setValue(Integer value) {
			this.value = value;
		}

		public String getDesc() {
			return desc;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}
	}

	/**
	 * 素材状态
	 */
	public enum MediaState {
		Uploading(0, "上传中"),
		UploadFail(2, "上传失败"),
		Transcoding(10, "转码中"),
		TranscodeFail(11, "转码失败"),
		Normal(1, "正常");

		private Integer value;
		private String desc;

		MediaState(Integer value, String desc) {
			this.value = value;
			this.desc = desc;
		}

		public static String getDescByValue(Integer value) {
			if (null == value) {
				return null;
			}
			for (AllowComment object : AllowComment.values()) {
				if (object.getValue().equals(value)) {
					return object.getDesc();
				}
			}
			return null;
		}

		public Integer value() {
			return value;
		}

		public void setValue(Integer value) {
			this.value = value;
		}

		public String desc() {
			return desc;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}
	}
	/**
	 * 素材来源
	 */
	public interface MediaSource {
		/**
		 * 直播录制
		 */
		Integer RECORD = 1;
		/**
		 * 素材上传
		 */
		Integer UPLOAD = 2;
		/**
		 * 合成
		 */
		Integer EDIT = 3;
	}

	/**
	 * 是否自动开关播
	 * */
	public interface IsAutoLive {
		/**
		 * 关闭
		 * */
		Integer CLOSE = 0;
		/**
		 * 开启
		 * */
		Integer OPEN = 1;
	}
	/**
	 * 是否删除
	 * */
	public interface IsDelete {
		/**
		 * 关闭
		 * */
		Integer NOTISDELETE = 0;
		/**
		 * 开启
		 * */
		Integer ISDELETE = 1;
	}
}
