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.HandleUtils;
import org.openqa.selenium.WebElement;

import java.util.concurrent.Callable;

public class MonkeyTestThread implements Callable<Boolean> {

    private IExecuteContext context;
    private DeviceDriver deviceDriver;
    private Float preExecuteWait;
    private Float sufExecuteWait;
    private Long execNum;
    private String packageName;
    private Integer seed;
    private Long throttle;
    private Integer touch;
    private Integer montion;
    private Integer pinchroom;
    private Integer trackball;
    private Integer ratation;
    private Integer nav;
    private Integer majornav;
    private Integer syskeys;
    private Integer appswitch;
    private Integer flip;
    private Integer anyevent;
    private Boolean ignoreCrashes;
    private Boolean ignoreTimeouts;
    private Boolean ignoreNativeCrashes;

    public MonkeyTestThread(IExecuteContext context, DeviceDriver deviceDriver, Float preExecuteWait, Float sufExecuteWait, Long execNum, String packageName, Integer seed, Long throttle, Integer touch, Integer montion, Integer pinchroom, Integer trackball, Integer ratation, Integer nav, Integer majornav, Integer syskeys, Integer appswitch, Integer flip, Integer anyevent, Boolean ignoreCrashes, Boolean ignoreTimeouts, Boolean ignoreNativeCrashes) {
        this.context = context;
        this.deviceDriver = deviceDriver;
        this.preExecuteWait = preExecuteWait;
        this.sufExecuteWait = sufExecuteWait;
        this.execNum = execNum;
        this.packageName = packageName;
        this.seed = seed;
        this.throttle = throttle;
        this.touch = touch;
        this.montion = montion;
        this.pinchroom = pinchroom;
        this.trackball = trackball;
        this.ratation = ratation;
        this.nav = nav;
        this.majornav = majornav;
        this.syskeys = syskeys;
        this.appswitch = appswitch;
        this.flip = flip;
        this.anyevent = anyevent;
        this.ignoreCrashes = ignoreCrashes;
        this.ignoreTimeouts = ignoreTimeouts;
        this.ignoreNativeCrashes = ignoreNativeCrashes;
    }

    @Override
    public Boolean call() throws Exception {
        CommonUtils.handlePreExecuteWait(preExecuteWait);
        AppiumDriver<WebElement> driver = (AppiumDriver<WebElement>) deviceDriver;
        HandleUtils.monkeyTest(context,driver,execNum,packageName,seed,throttle,touch,montion,pinchroom,trackball,ratation,nav,majornav,syskeys,appswitch,flip,anyevent,ignoreCrashes,ignoreTimeouts,ignoreNativeCrashes);
        CommonUtils.handleSufExecuteWait(sufExecuteWait);
        return true;
    }
}
