package com.czg.cashier_reserve.call;

import android.content.Context;
import android.content.Intent;

import com.czg.cashier_reserve.ContextHolder;
import com.czg.cashier_reserve.channel.EventChannelManager;
import com.kaer.subutil.contact.ContactBean;
import com.kaer.subutil.contact.ContactUtil;

import org.json.JSONObject;

import cn.kaer.callmodule.Call;
import cn.kaer.callmodule.CoreListenerStub;
import cn.kaer.callmodule.ctrl.BaseController;
import io.flutter.Log;

public class YJCoreListenerStub extends CoreListenerStub {

	public void onCallStateChanged(BaseController var1, Call var2, Call.State var3, String var4) {
		ContactBean contactInfo = ContactUtil.getContactInfo(ContextHolder.getInstance().getContext(), var2.getRemoteNumber());
		Log.i("YJCoreListenerStub", "onCallStateChanged +++ " + var3);

		JSONObject callInfo = new JSONObject();
		try {
			callInfo.put("state", var3);
			callInfo.put("number", var2.getRemoteNumber());
			callInfo.put("name", contactInfo.getcName());
			callInfo.put("region", contactInfo.getRegion());
		} catch (Exception e) {
			e.printStackTrace();
		}

		Log.i("YJCoreListenerStub", "onCallStateChanged: " + callInfo);

		Context mainActivityContext = ContextHolder.getInstance().getContext();
		Intent broad = new Intent(EventChannelManager.Action.CALL_STATUS_CHANGE);
		broad.putExtra("callStatus", callInfo.toString());
		mainActivityContext.sendBroadcast(broad);
	}
}
