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 VideoUtil {

    public static TcpModel videoCalling(Integer fromId, Integer toId, Integer interactionId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VIDEO);
        tcpModel.setAction(TcpAction.VideoAction.CALLING);
        tcpModel.setFromId(fromId);
        tcpModel.setToId(toId);
        tcpModel.setData(interactionId);
        return tcpModel;
    }

    public static TcpModel videoOutCall(Integer fromId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VIDEO);
        tcpModel.setAction(TcpAction.VideoAction.VIDEO_OUT_CALL);
        tcpModel.setFromId(fromId);
        return tcpModel;
    }

    public static TcpModel videoCancelCall(Integer fromId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VIDEO);
        tcpModel.setAction(TcpAction.VideoAction.CANCEL);
        tcpModel.setFromId(fromId);
        return tcpModel;
    }

    public static TcpModel videoReject(Integer fromId, Integer toId,Integer interactionId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VIDEO);
        tcpModel.setAction(TcpAction.VideoAction.REJECT);
        tcpModel.setFromId(fromId);
        tcpModel.setToId(toId);
        tcpModel.setData(interactionId);
        return tcpModel;
    }

    public static TcpModel videoAccept(Integer fromId, Integer toId,Integer interactionId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VIDEO);
        tcpModel.setAction(TcpAction.VideoAction.ACCEPT);
        tcpModel.setFromId(fromId);
        tcpModel.setToId(toId);
        tcpModel.setData(interactionId);
        return tcpModel;
    }

    public static TcpModel videoInvite(Integer fromId, Integer toId, Integer interactionId, String roomId) {
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VIDEO);
        tcpModel.setAction(TcpAction.VideoAction.VIDEO_INVITE_JOIN);
        tcpModel.setFromId(fromId);
        tcpModel.setToId(toId);
        Map map = new HashMap();
        map.put("interactionId", interactionId);
        map.put("roomId", roomId);
        tcpModel.setData(map);
        return tcpModel;
    }

    public static TcpModel videoHandoff(Integer fromId, Integer toId, Integer interactionId){
        TcpModel tcpModel = new TcpModel();
        tcpModel.setType(TcpType.VIDEO);
        tcpModel.setAction(TcpAction.VideoAction.HANDOFF);
        tcpModel.setFromId(fromId);
        tcpModel.setToId(toId);
        tcpModel.setData(interactionId);
        return tcpModel;
    }


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

    //请求视频通话
    public static void startVideoOutCall(Integer fromId) {
        TcpModel tcpModel = videoOutCall(fromId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }

    //拒绝视频
    public static void rejectVideoCall(Integer fromId, Integer toId, Integer interactionId) {
        TcpModel tcpModel = videoReject(fromId, toId, interactionId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }

    //取消视频
    public static void cancelVideoCall(Integer fromId) {
        TcpModel tcpModel = videoCancelCall(fromId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }

    //接受视频
    public static void acceptVideoCall(Integer fromId, Integer toId, Integer interactionId) {
        TcpModel tcpModel = videoAccept(fromId, toId, interactionId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }

    //发送视频探视邀请
    public static void sendInviteVideoCall(Integer fromId, Integer toId, Integer interactionId, String roomId) {
        TcpModel tcpModel = videoInvite(fromId, toId, interactionId, roomId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }

    //挂断视频
    public static void handoffVideoCall(Integer fromId, Integer toId, Integer interactionId) {
        TcpModel tcpModel = videoHandoff(fromId, toId, interactionId);
        TcpClient.getInstance().sendMsg(tcpModel.toJson());
    }
}
