package im.actor.core.viewmodel;

import com.google.j2objc.annotations.Property;

import java.util.ArrayList;

import im.actor.core.entity.Peer;
import im.actor.core.viewmodel.generics.BooleanValueModel;
import im.actor.core.viewmodel.generics.IntValueModel;
import im.actor.runtime.*;
import im.actor.runtime.actors.ActorTime;
import im.actor.runtime.mvvm.ValueModel;
import im.actor.runtime.threading.CommonTimer;

public class CallVM {

    @Property("nonatomic, readonly")
    private final long callId;
    @Property("nonatomic, readonly")
    private final Peer peer;
    @Property("nonatomic, readonly")
    private final ValueModel<CallState> state;
    @Property("nonatomic, readonly")
    private final ValueModel<ArrayList<CallMember>> members;
    @Property("nonatomic, readonly")
    private final BooleanValueModel isMuted;
    @Property("nonatomic, readonly")
    private long callStart;
    @Property("nonatomic, readonly")
    private long callEnd;
    @Property("nonatomic, readonly")
    private final boolean isOutgoing;

    private CommonTimer presenceTimer;

    public CallVM(long callId, Peer peer, boolean isOutgoing, ArrayList<CallMember> initialMembers, CallState state) {
        this.callId = callId;
        this.peer = peer;
        this.isOutgoing = isOutgoing;
        this.state = new ValueModel<>("calls." + callId + ".state", state);
        this.members = new ValueModel<>("calls." + callId + ".members", new ArrayList<>(initialMembers));
        this.isMuted = new BooleanValueModel("calls." + callId + ".state", false);
        this.callStart = 0;
    }

    public boolean isOutgoing() {
        return isOutgoing;
    }

    public Peer getPeer() {
        return peer;
    }

    public long getCallId() {
        return callId;
    }

    public BooleanValueModel getIsMuted() {
        return isMuted;
    }

    public ValueModel<CallState> getState() {
        return state;
    }

    public ValueModel<ArrayList<CallMember>> getMembers() {
        return members;
    }

    public void setCallStart(long callStart) {
        this.callStart = callStart;
    }

    public long getCallStart() {
        return callStart;
    }

    public long getCallEnd() {
        return callEnd;
    }

    public void setCallEnd(long callEnd) {
        this.callEnd = callEnd;
    }
}
@@ -408,16 +408,69 @@
 onTimer;
+%0Aimport im.actor.runtime.webrtc.WebRTCPeerConnection;
 %0A%0Apublic
@@ -733,32 +733,136 @@
 mic, readonly%22)%0A
+    private final ValueModel%3CWebRTCPeerConnection%3E peerConnection;%0A    @Property(%22nonatomic, readonly%22)%0A
     private fina
@@ -1517,24 +1517,118 @@
 e%22, state);%0A
+        this.peerConnection = new ValueModel%3C%3E(%22calls.%22 + callId + %22.peer_connection%22, null);%0A
         this

add peer connection to call vm