/*
 * This is the source code of Telegram for Android v. 3.x.x.
 * It is licensed under GNU GPL v. 2 or later.
 * You should have received a copy of the license in this archive (see LICENSE).
 *
 * Copyright Grishka, 2013-2016.
 */

package org.telegram.messenger.voip;



import org.telegram.tgnet.TLRPC;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Locale;

public class VoIPController{



    protected long nativeInst=0;
    protected long callStartTime;
    protected ConnectionStateListener listener;

    public VoIPController(){
      //  nativeInst=nativeInit(new File(ApplicationLoader.applicationContext.getFilesDir(), "voip_persistent_state.json").getAbsolutePath());
    }

    public void start(){

    }

    public void connect(){

    }

    public void setRemoteEndpoints(TLRPC.TL_phoneConnection[] endpoints, boolean allowP2p, boolean tcp, int connectionMaxLayer){

    }

    public void setEncryptionKey(byte[] key, boolean isOutgoing){

    }

    public static void setNativeBufferSize(int size){

    }

    public void release(){

    }

    public String getDebugString(){
      return "";
    }

    protected void ensureNativeInstance(){

    }

    public void setConnectionStateListener(ConnectionStateListener connectionStateListener){
        listener=connectionStateListener;
    }

    // called from native code
    private void handleStateChange(int state){

    }

    // called from native code
    private void handleSignalBarsChange(int count) {

    }

    // called from native code
    private void groupCallKeyReceived(byte[] key){

    }

    // called from native code
    private void groupCallKeySent(){

    }

    // called from native code
    private void callUpgradeRequestReceived(){

    }

    public void setNetworkType(int type){

    }

    public long getCallDuration(){
      return 0;
    }

    public void setMicMute(boolean mute){

    }

    public void setConfig(double recvTimeout, double initTimeout, int dataSavingOption, long callID){

    }

    public void debugCtl(int request, int param){

    }

    public long getPreferredRelayID() {
        return 0;
    }

    public int getLastError(){
        return 0;
    }

    public void getStats(Stats stats){

    }

    public static String getVersion(){
        return "";
    }

    private String getLogFilePath(String name) {
        return "";
    }

    private String getLogFilePath(long callID){
     return ";";
    }

    public String getDebugLog(){
       return "";
    }

    public void setProxy(String address, int port, String username, String password){

    }

    public void setAudioOutputGainControlEnabled(boolean enabled){

    }

    public int getPeerCapabilities(){
      return 0;
    }

    public void sendGroupCallKey(byte[] key){

    }

    public void requestCallUpgrade(){

    }

    public void setEchoCancellationStrength(int strength){

    }

    public boolean needRate(){
      return true;
    }

    private native long nativeInit(String persistentStateFile);
    private native void nativeStart(long inst);
    private native void nativeConnect(long inst);
    private static native void nativeSetNativeBufferSize(int size);
    private native void nativeSetRemoteEndpoints(long inst, TLRPC.TL_phoneConnection[] endpoints, boolean allowP2p, boolean tcp, int connectionMaxLayer);
    private native void nativeRelease(long inst);
    private native void nativeSetNetworkType(long inst, int type);
    private native void nativeSetMicMute(long inst, boolean mute);
    private native void nativeDebugCtl(long inst, int request, int param);
    private native void nativeGetStats(long inst, Stats stats);
    private native void nativeSetConfig(long inst, double recvTimeout, double initTimeout, int dataSavingOption, boolean enableAEC, boolean enableNS, boolean enableAGC, String logFilePath, String statsDumpPath, boolean logPacketStats);
    private native void nativeSetEncryptionKey(long inst, byte[] key, boolean isOutgoing);
    private native void nativeSetProxy(long inst, String address, int port, String username, String password);
    private native long nativeGetPreferredRelayID(long inst);
    private native int nativeGetLastError(long inst);
    private native String nativeGetDebugString(long inst);
    private static native String nativeGetVersion();
    private native void nativeSetAudioOutputGainControlEnabled(long inst, boolean enabled);
    private native void nativeSetEchoCancellationStrength(long inst, int strength);
    private native String nativeGetDebugLog(long inst);
    private native int nativeGetPeerCapabilities(long inst);
    private native void nativeSendGroupCallKey(long inst, byte[] key);
    private native void nativeRequestCallUpgrade(long inst);
    private static native boolean nativeNeedRate(long inst);
    public static native void nativeSetVideoSource(long arg1, long arg2);
    public static native void nativeSetVideoRenderer(long arg1, long arg2);

    public static native int getConnectionMaxLayer();

    public interface ConnectionStateListener{
        void onConnectionStateChanged(int newState);
        void onSignalBarCountChanged(int newCount);
        void onGroupCallKeyReceived(byte[] key);
        void onGroupCallKeySent();
        void onCallUpgradeRequestReceived();
    }

    public static class Stats{
        public long bytesSentWifi;
        public long bytesRecvdWifi;
        public long bytesSentMobile;
        public long bytesRecvdMobile;

        @Override
        public String toString(){
            return "Stats{"+
                    "bytesRecvdMobile="+bytesRecvdMobile+
                    ", bytesSentWifi="+bytesSentWifi+
                    ", bytesRecvdWifi="+bytesRecvdWifi+
                    ", bytesSentMobile="+bytesSentMobile+
                    '}';
        }
    }
}