package net.northking.cctp.element.mobile.thread;

import io.appium.java_client.AppiumDriver;
import net.northking.cctp.element.core.DeviceDriver;
import net.northking.cctp.element.core.IExecuteContext;
import net.northking.cctp.element.mobile.utils.CommonUtils;
import net.northking.cctp.element.mobile.utils.phoneUtils.AppUtil;
import org.openqa.selenium.WebElement;

import java.util.concurrent.Callable;

public class AppHandleThread implements Callable<Boolean> {

    private IExecuteContext context;
    private DeviceDriver deviceDriver;
    private Integer waitTimeout;
    private String appPackage;
    private String type;
    private Float preExecuteWait;
    private Float sufExecuteWait;

    public AppHandleThread(IExecuteContext context,DeviceDriver deviceDriver, Integer waitTimeout, String appPackage, String type, Float preExecuteWait, Float sufExecuteWait) {
        this.context = context;
        this.deviceDriver = deviceDriver;
        this.waitTimeout = waitTimeout;
        this.appPackage = appPackage;
        this.type = type;
        this.preExecuteWait = preExecuteWait;
        this.sufExecuteWait = sufExecuteWait;
    }

    @Override
    public Boolean call() throws Exception {
        CommonUtils.handlePreExecuteWait(preExecuteWait);
        AppiumDriver<WebElement> driver = (AppiumDriver<WebElement>) deviceDriver;
        boolean b = AppUtil.handleApp(context, driver, appPackage, waitTimeout, type);
        CommonUtils.handleSufExecuteWait(sufExecuteWait);
        return b;
    }
}
