package com.wdkl.ncs.android.middleware.tcp.channel;

import com.wdkl.ncs.android.middleware.tcp.TcpClient;
import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel;
import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction;
import com.wdkl.ncs.android.middleware.tcp.enums.TcpType;

import java.util.HashMap;
import java.util.Map;

public class VoiceUtil {
    //分机呼叫，不需要传toId
    public static TcpModel voiceCall(Integer fromId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VOICE);
        tcpModel.setAction(TcpAction.VoiceAction.CALL);
        tcpModel.setFromId(fromId);
        return tcpModel;
    }

    public static TcpModel voiceAccept(Integer fromId, Integer toId, Integer interactionId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VOICE);
        tcpModel.setAction(TcpAction.VoiceAction.ACCEPT);
        tcpModel.setFromId(fromId);
        tcpModel.setToId(toId);
        if (interactionId != -1) {
            tcpModel.setData(interactionId);
        }
        return tcpModel;
    }

    public static TcpModel voiceReject(Integer fromId, Integer toId, Integer interactionId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VOICE);
        tcpModel.setAction(TcpAction.VoiceAction.REJECT);
        tcpModel.setFromId(fromId);
        tcpModel.setToId(toId);
        if (interactionId != -1) {
            tcpModel.setData(interactionId);
        }
        return tcpModel;
    }

    public static TcpModel voiceCalling(Integer fromId, Integer toId, Integer interactionId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VOICE);
        tcpModel.setAction(TcpAction.VoiceAction.CALLING);
        tcpModel.setFromId(fromId);
        tcpModel.setToId(toId);
        if (interactionId != -1) {
            tcpModel.setData(interactionId);
        }
        return tcpModel;
    }

    //分机自己取消呼叫,没有toId
    public static TcpModel voiceCancel(Integer fromId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VOICE);
        tcpModel.setAction(TcpAction.VoiceAction.CANCEL);
        tcpModel.setFromId(fromId);
        return tcpModel;
    }

    public static TcpModel voiceHandoff(Integer fromId, Integer toId, Integer interactionId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VOICE);
        tcpModel.setAction(TcpAction.VoiceAction.HANDOFF);
        tcpModel.setFromId(fromId);
        if (toId != -1) {
            tcpModel.setToId(toId);
        }
        if (interactionId != -1) {
            tcpModel.setData(interactionId);
        }
        return tcpModel;
    }

    public static TcpModel voiceSuccess(Integer fromId, Integer toId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VOICE);
        tcpModel.setAction(TcpAction.VoiceAction.SUCCESS);
        tcpModel.setFromId(fromId);
        tcpModel.setToId(toId);
        return tcpModel;
    }

    /**************************************************************************
     ************************* 发送呼叫相关TCP *********************************
    ***************************************************************************/
    //语音呼叫
    public static void startAudioCall(Integer fromId) {
        TcpModel tcpModel = VoiceUtil.voiceCall(fromId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }

    //取消呼叫
    public static void cancelAudioCall(Integer fromId) {
        TcpModel tcpModel = VoiceUtil.voiceCancel(fromId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }

    //接受通话
    public static void acceptAudioCall(Integer fromId, Integer toId, Integer interactionId) {
        TcpModel tcpModel = VoiceUtil.voiceAccept(fromId, toId, interactionId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }

    //挂断通话
    public static void handoffAudioCall(Integer fromId, Integer toId, Integer interactionId) {
        TcpModel tcpModel = VoiceUtil.voiceHandoff(fromId, toId, interactionId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }

    //拒绝通话
    public static void rejectAudioCall(Integer fromId, Integer toId, Integer interactionId) {
        TcpModel tcpModel = VoiceUtil.voiceReject(fromId, toId, interactionId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }

    public static void inAudioCall(Integer fromId, Integer toId, Integer interactionId) {
        TcpModel tcpModel = VoiceUtil.voiceCalling(fromId, toId, interactionId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }
}
