package net.northking.cctp.upperComputer.automation.handler;

import net.northking.cctp.upperComputer.automation.entity.CmdAutomationRequest;
import net.northking.cctp.upperComputer.automation.entity.CmdAutomationResponse;
import net.northking.cctp.upperComputer.driver.adb.Adb;
import net.northking.cctp.upperComputer.driver.adb.AdbDevice;
import net.northking.cctp.upperComputer.driver.agent.AndroidAgentSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.websocket.Session;
import java.io.IOException;

/**
 * @author : yineng.huang
 * @date : 2024/4/16 19:59
 */
public class AndroidAutomationHandler extends AbstractAutomationHandler{

    private final Logger logger = LoggerFactory.getLogger(AndroidAutomationHandler.class);

    private AdbDevice adbDevice;

    private Adb adb;  //adb执行命令所用

    private AndroidAgentSession asyncAgentSession;//异步处理设备指令的AgentSession

    private AndroidAgentSession syncAgentSession;  //同步处理设备指令的AgentSession

    public AndroidAutomationHandler(AdbDevice currentDevice,Session session) throws IOException {
        this.adbDevice = currentDevice;
        this.serial = currentDevice.getSerial();
        this.engineSession = session;
        adb = new Adb();
        asyncAgentSession = new AndroidAgentSession(adbDevice, true);
        asyncAgentSession.start();
        syncAgentSession = new AndroidAgentSession(adbDevice, false);
        syncAgentSession.start();
        logger.info("设备【{}】自动化驱动创建完成.........", adbDevice.getSerial());
    }

    @Override
    public void destroy() {
        if (null != asyncAgentSession) {
            asyncAgentSession.closeSilence();
        }
        if (null != syncAgentSession) {
            syncAgentSession.closeSilence();
        }
        logger.warn("设备【{}】的自动化驱动已经销毁关闭............", adbDevice.getSerial());
    }

    @Override
    public void openMobileNotificationBar(CmdAutomationRequest request) {
        adb.shell(adbDevice, "cmd statusbar expand-notifications");
        CmdAutomationResponse response = CmdAutomationResponse.builderSuccess(request, "打开通知栏成功");
        response.withData(true);
        sendResultToEngine(response);
    }

    @Override
    public void closeMobileNotificationBar(CmdAutomationRequest request) {
        adb.shell(adbDevice, "cmd statusbar collapse");
        CmdAutomationResponse response = CmdAutomationResponse.builderSuccess(request, "关闭通知栏成功");
        sendResultToEngine(response);
    }

    @Override
    public void initApplication(CmdAutomationRequest request) {

    }

    @Override
    public void clickPoint(CmdAutomationRequest request) {

    }

    @Override
    public void searchNodeByNodeTree(CmdAutomationRequest request) {

    }

    @Override
    public void searchNodeByPoint(CmdAutomationRequest request) {

    }

    @Override
    public void searchNodeByOcr(CmdAutomationRequest request) {

    }

    @Override
    public void searchNodeByImage(CmdAutomationRequest request) {

    }

    @Override
    public void getElementValueByNode(CmdAutomationRequest request) {

    }

    @Override
    public void getElementValueByOcr(CmdAutomationRequest request) {

    }

    @Override
    public void getVerificationCodeByNode(CmdAutomationRequest request) {

    }

    @Override
    public void getVerificationCodeByOcr(CmdAutomationRequest request) {

    }

    @Override
    public void longPress(CmdAutomationRequest request) {

    }

    @Override
    public void swipe(CmdAutomationRequest request) {

    }

    @Override
    public void inputText(CmdAutomationRequest request) {

    }

    @Override
    public void handleNodeByNodeTree(CmdAutomationRequest request) {

    }

    @Override
    public void handleNodeByPoint(CmdAutomationRequest request) {

    }

    @Override
    public void handleNodeByOcr(CmdAutomationRequest request) {

    }

    @Override
    public void handleNodeByImage(CmdAutomationRequest request) {

    }

    @Override
    public void clickTextByOcr(CmdAutomationRequest request) {

    }

    @Override
    public void clickTextByOcrNew(CmdAutomationRequest request) {

    }

    @Override
    public void ifText(CmdAutomationRequest request) {

    }

    @Override
    public void handleApp(CmdAutomationRequest request) {

    }

    @Override
    public void pressHomeKey(CmdAutomationRequest request) {

    }

    @Override
    public void inputPasswordByOcr(CmdAutomationRequest request) {

    }

    @Override
    public void getElementMoneyText(CmdAutomationRequest request) {

    }

    @Override
    public void screenShot(CmdAutomationRequest request) {

    }

    @Override
    public void getElementValueByPathOcr(CmdAutomationRequest request) {

    }


    @Override
    public void pressAndSwipe(CmdAutomationRequest request) {

    }
}
