/*
 * (C) Copyright 2017-2020 OpenVidu (https://openvidu.io)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package io.openvidu.server.recording;

import org.kurento.client.RecorderEndpoint;

import com.google.gson.JsonObject;

import io.openvidu.server.kurento.core.KurentoParticipant;

public class RecorderEndpointWrapper {

	private RecorderEndpoint recorder;
	private KurentoParticipant kParticipant;
	private String recordingId;

	private long startTime;
	private long endTime;
	private long size;

	public RecorderEndpointWrapper(RecorderEndpoint recorder, KurentoParticipant kParticipant, String recordingId) {
		this.recorder = recorder;
		this.kParticipant = kParticipant;
		this.recordingId = recordingId;
	}

	public RecorderEndpoint getRecorder() {
		return recorder;
	}
	
	public KurentoParticipant getParticipant() {
		return this.kParticipant;
	}

	public String getConnectionId() {
		return kParticipant.getParticipantPublicId();
	}

	public String getRecordingId() {
		return recordingId;
	}

	public String getStreamId() {
		return kParticipant.getPublisherStreamId();
	}

	public String getClientData() {
		return kParticipant.getClientMetadata();
	}

	public String getServerData() {
		return kParticipant.getServerMetadata();
	}

	public long getStartTime() {
		return startTime;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

	public long getEndTime() {
		return endTime;
	}

	public void setEndTime(long endTime) {
		this.endTime = endTime;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public boolean hasAudio() {
		return kParticipant.getPublisher().getMediaOptions().hasAudio();
	}

	public boolean hasVideo() {
		return kParticipant.getPublisher().getMediaOptions().hasVideo();
	}

	public String getTypeOfVideo() {
		return kParticipant.getPublisher().getMediaOptions().getTypeOfVideo();
	}

	public JsonObject toJson() {
		JsonObject json = new JsonObject();
		json.addProperty("connectionId", this.getConnectionId());
		json.addProperty("streamId", this.getStreamId());
		json.addProperty("clientData", this.getClientData());
		json.addProperty("serverData", this.getServerData());
		json.addProperty("startTime", this.getStartTime());
		json.addProperty("endTime", this.getEndTime());
		json.addProperty("duration", this.getEndTime() - this.getStartTime());
		json.addProperty("size", this.getSize());
		json.addProperty("hasAudio", this.hasAudio());
		json.addProperty("hasVideo", this.hasVideo());
		if (this.hasVideo()) {
			json.addProperty("typeOfVideo", this.getTypeOfVideo());
		}
		return json;
	}

}

@@ -932,27 +932,222 @@
  String 
-recordingId
+connectionId;%0A%09private String recordingId;%0A%09private String streamId;%0A%09private String clientData;%0A%09private String serverData;%0A%09private boolean hasAudio;%0A%09private boolean hasVideo;%0A%09private String typeOfVideo
 ;%0A%0A%09priv
@@ -1414,32 +1414,493 @@
  = recordingId;%0A
+%09%09this.connectionId = kParticipant.getParticipantPublicId();%0A%09%09this.streamId = kParticipant.getPublisherStreamId();%0A%09%09this.clientData = kParticipant.getClientMetadata();%0A%09%09this.serverData = kParticipant.getServerMetadata();%0A%09%09this.hasAudio = kParticipant.getPublisher().getMediaOptions().hasAudio();%0A%09%09this.hasVideo = kParticipant.getPublisher().getMediaOptions().hasVideo();%0A%09%09this.typeOfVideo = kParticipant.getPublisher().getMediaOptions().getTypeOfVideo();%0A
 %09%7D%0A%0A%09public Reco
@@ -1950,17 +1950,16 @@
 der;%0A%09%7D%0A
-%09
 %0A%09public
@@ -2077,45 +2077,20 @@
 urn 
-kParticipant.getParticipantPublicId()
+connectionId
 ;%0A%09%7D
@@ -2195,43 +2195,16 @@
 urn 
-kParticipant.getPublisherS
+s
 treamId
-()
 ;%0A%09%7D
@@ -2251,40 +2251,18 @@
 urn 
-kParticipant.getClientMetad
+clientD
 ata
-()
 ;%0A%09%7D
@@ -2309,40 +2309,18 @@
 urn 
-kParticipant.getServerMetad
+serverD
 ata
-()
 ;%0A%09%7D
@@ -2717,62 +2717,16 @@
 urn 
-kParticipant.getPublisher().getMediaOptions().
 hasAudio
 ();%0A
@@ -2721,18 +2721,16 @@
 hasAudio
-()
 ;%0A%09%7D%0A%0A%09p
@@ -2769,62 +2769,16 @@
 urn 
-kParticipant.getPublisher().getMediaOptions().
 hasVideo
 ();%0A
@@ -2769,26 +2769,24 @@
 urn hasVideo
-()
 ;%0A%09%7D%0A%0A%09publi
@@ -2826,58 +2826,9 @@
 urn 
-kParticipant.getPublisher().getMediaOptions().getT
+t
 ypeO
@@ -2825,34 +2825,32 @@
 turn typeOfVideo
-()
 ;%0A%09%7D%0A%0A%09public Js

rollback RecorderEndpointWrapper