package cn.tee3.avd;

/**
 * 房间信息结构.
 *
 * 房间信息定义了安排房间时的所有信息。
 */
public class RoomInfo {
    /** 房间模式 */
    private static final int RoomMode_clear_set = (1 << 0); // use internal
    public static final int RoomMode_mcu = (1 << 31);                                       /**< mcu模式  */
    public static final int RoomMode_p2p = RoomMode_mcu + RoomMode_clear_set;               /**< p2p模式  */
    public static final int RoomMode_rm_attr_netacc = (1 << 2);				/**< 房间中网络加速，暂不支持  */
    public static final int RoomMode_rm_attr_netacc_close = RoomMode_rm_attr_netacc + RoomMode_clear_set;/**< 房间中网络没有加速，暂不支持 */
    public static final int RoomMode_rm_attr_hostcontrol = (1 << 3);    	/**< 房间是场控模式，严格控制房间中的音视频，参会者默认没有音视频打开权限  */
    public static final int RoomMode_rm_attr_freespeech = RoomMode_rm_attr_hostcontrol + RoomMode_clear_set;/**< 房间是自由发言模式，默认  */


    /** 房间状态 */
    public static enum RoomStatus
    {
        scheduled,                          /**< 已经安排好  */
        opening,                            /**< 正在进行中  */
        locked,                             /**< 已锁定房间：锁定房间后，新用户无法加入房间  */
        closed,                             /**< 已关闭房间  */
    };

    String	roomId;                         /**< 房间Id */
    String	roomName;                       /**< 房间名 */
    String	appRoomId;                      /**< 房间应用层Id */
    String  roomTopic;                      /**< 房间主题 */
    String ownerId;                         /**< 房间创建者Id */
    String	hostId;                         /**< 房间主持人Id */
    String  hostPassword;                   /**< 房间主持人密码 */
	String  confPassword;                   /**< 房间密码，必须与主持人密码不同 */
    int		startTime;                      /**< 房间起始时间 */
    int		duration;                       /**< 房间延续时间 */
    int		bandwidth;                      /**< 房间带宽限制 */
    int		maxAttendee;                    /**< 房间最大用户数限制 */
    int		maxAudio;                       /**< 房间最大音频数限制 */
    int		maxVideo;                       /**< 房间最大视频数限制 */
    int     roomMode;                       /**< 房间模式集 */
    boolean enableVoiceActivated;           /**< 房间开启语音激励*/
    ///
    public RoomInfo(String roomId, String appRoomId, String roomName, String roomTopic, String ownerId , String hostId, String hostPass, String confPass,
                    int startTime, int duration, int roomMode, int bandwidth, int maxAttendee, int maxAudio, int maxVideo) {
        this.roomId = (roomId == null) ? "" :roomId;
		this.appRoomId = (appRoomId == null) ? "" :appRoomId;
        this.roomName = (roomName == null) ? "" :roomName;
        this.roomTopic = (roomTopic == null) ? "" :roomTopic;
        this.ownerId = (ownerId == null) ? "" :ownerId;
        this.hostId = (hostId == null) ? "" :hostId;
        this.hostPassword = (hostPass == null) ? "" :hostPass;
        this.confPassword = (confPass == null) ? "" :confPass;
        this.startTime = startTime;
        this.duration = duration;
        this.roomMode = roomMode;
        this.bandwidth = bandwidth;
        this.maxAttendee = maxAttendee;
        this.maxAudio = maxAudio;
        this.maxVideo = maxVideo;
    }
    public RoomInfo(String appRoomId, int roomMode, int maxAttendee) {
        this.setZero();
        this.roomId = (roomId == null) ? "" :roomId;
        this.appRoomId = (appRoomId == null) ? "" :appRoomId;
        this.roomName = (roomName == null) ? "" :roomName;
        this.roomMode = roomMode;
        this.maxAttendee = maxAttendee;
        this.maxAudio = maxAttendee;
        this.maxVideo = maxAttendee;
    }
    public RoomInfo(String appRoomId) {
        this.setZero();
        this.appRoomId = appRoomId;
        this.roomId = appRoomId;
        this.roomName = appRoomId;
        this.ownerId = appRoomId;
        this.roomMode = RoomMode_mcu;
        this.maxAttendee = 100;
        this.maxAudio = 100;
        this.maxVideo = 100;
    }

    public RoomInfo(String appRoomId, boolean enableVoiceActivated) {
        this.setZero();
        this.appRoomId = appRoomId;
        this.roomId = appRoomId;
        this.roomName = appRoomId;
        this.ownerId = appRoomId;
        this.roomMode = RoomMode_mcu;
        this.maxAttendee = 100;
        this.maxAudio = 100;
        this.maxVideo = 100;
        this.enableVoiceActivated = enableVoiceActivated;
    }

    public RoomInfo(String appRoomId, boolean enableVoiceActivated, String hostId) {
        this.setZero();
        this.appRoomId = appRoomId;
        this.roomId = appRoomId;
        this.roomName = appRoomId;
        this.ownerId = hostId;
        this.hostId = hostId;
        this.roomMode = RoomMode_mcu;
        this.maxAttendee = 100;
        this.maxAudio = 100;
        this.maxVideo = 100;
        this.enableVoiceActivated = enableVoiceActivated;
    }

	public RoomInfo() {
        this.roomId = "";
		this.appRoomId = "";
        this.roomName = "";
        this.roomTopic = "";
        this.ownerId = "";
        this.hostId = "";
        this.hostPassword = "";
        this.confPassword = "";
        this.startTime = 0;
        this.duration = 0;
        this.roomMode = 0;
        this.maxAttendee = 0;
        this.bandwidth = 0;
        this.maxAudio = 0;
        this.maxVideo = 0;
    }
    private void setZero() {
        this.roomId = "";
        this.appRoomId = "";
        this.roomName = "";
        this.roomTopic = "";
        this.ownerId = "";
        this.hostId = "";
        this.hostPassword = "";
        this.confPassword = "";
        this.startTime = 0;
        this.duration = 0;
        this.roomMode = 0;
        this.maxAttendee = 0;
        this.bandwidth = 0;
        this.maxAudio = 0;
        this.maxVideo = 0;
    }
    public String getRoomId() {
		return roomId;
    }
	public String getAppRoomId() {
		return appRoomId;
    }
    public String getRoomName() {
        return roomName;
    }
    public String getRoomTopic() {
        return roomTopic;
    }
    public String getOwnerId() {
		return ownerId;
    }
    public String getHostId() {
        return hostId;
    }
    public String getConfPassword() {
		return hostPassword;
    }
    public String getHostPassword() {
        return confPassword;
    }
    public int getStartTime() {
        return startTime;
    }
    public int getDuration() {
		return duration;
    }
    public int getRoomMode() {
        return roomMode;
    }
    public int getMaxAttendee() {
		return maxAttendee;
    }
    public int getBandwidth() {
		return bandwidth;
    }
    public int getMaxAudio() {
        return maxAudio;
    }
    public int getMaxVideo() {
        return maxVideo;
    }
    public void setRoomId(String value) {
        this.roomId = (value == null) ? "" : value;
    }
	public void setAppRoomId(String value) {
        this.appRoomId = (value == null) ? "" : value;
    }
    public void setRoomTopic(String value) {
        this.roomTopic = (value == null) ? "" : value;
    }
    public void setRoomName(String value) {
        this.roomName = (value == null) ? "" : value;
    }
    public void setOwnerId(String value) {
        this.ownerId = (value == null) ? "" : value;
    }
    public void setHostId(String value) {
        this.hostId = (value == null) ? "" : value;
    }
    public void setConfPassword(String value) {
        this.confPassword = (value == null) ? "" : value;
    }
    public void setHostPassword(String hostPass) {
        this.hostPassword = (hostPass == null) ? "" : hostPass;
    }
    public void setStartTime(int value) {
        this.startTime = value;
    }
    public void setDuration(int value) {
        this.duration = value;
    }
    public void setMaxAttendee(int value) {
        this.maxAttendee = value;
    }
    public void setBandwidth(int value) {
        this.bandwidth = value;
    }
    public void setMaxAudio(int value) {
        this.maxAudio = value;
    }
    public void setMaxVideo(int value) {
        this.maxVideo = value;
    }
    //
    /** 判断是mcu模式房间 */
    public boolean isMcu() {
        return RolePrivilege.hasFlag(roomMode,RoomMode_mcu);
    }
    /** 设置房间模式
     * @param[in] flag 设置值。
     */
    public void setRoomMode(int flag) {
        if (RolePrivilege.hasFlag(flag, RoomMode_clear_set)) {
            roomMode = RolePrivilege.clearFlag(flag, RoomMode_clear_set);
            roomMode = RolePrivilege.clearFlag(roomMode, flag);
        }
        else {
            roomMode = RolePrivilege.setFlag(roomMode, flag);
        }
    }
    public boolean hasMode(int mode) {
        if (RolePrivilege.hasFlag(mode, RoomMode_clear_set)) {
            int dwFlag = mode;
            dwFlag = RolePrivilege.clearFlag(dwFlag, RoomMode_clear_set);
            return !RolePrivilege.hasFlag(roomMode, dwFlag);
        }
        else {
            return RolePrivilege.hasFlag(roomMode, mode);
        }
    }

    @Override
    public boolean equals(Object obj) {
        RoomInfo objd = (RoomInfo) obj;
        if (null == objd) {
            return false;
        }
        return objd.getRoomId().equals(this.getRoomId());
    }
    @Override
    public String toString() {
        return "Room: id=" + this.roomId + ",mode="+this.roomMode + ",maxu="+this.maxAttendee + ",maxa="+this.maxAudio+",maxv="+this.getMaxVideo() +", enableVoiceActivated="+this.enableVoiceActivated;
    }
}
