package net.northking.cctp.se.device.bean;

import io.appium.java_client.ios.IOSDriver;
import net.northking.cctp.element.core.DeviceDriver;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URL;
import java.util.concurrent.Future;

public class IosMobileDeviceDriver extends IOSDriver<WebElement> implements DeviceDriver {

    private Future future;

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

    public IosMobileDeviceDriver(URL remoteAddress, Capabilities desiredCapabilities) {
        super(remoteAddress, desiredCapabilities);
        logger.info("Mobile iosDriver created --> [address:{},capability:{}]", remoteAddress, desiredCapabilities);
    }

    @Override
    public void destroy() {
        try {
            this.quit();
        } catch (Exception e) {
            logger.warn("driver有问题");
        }
        if (null != this.future) {
            this.future.cancel(true);
            this.future = null;
        }
        logger.info("iosDriver driver destroyed. ");
    }

    @Override
    public void setFuture(Future future) {
        this.future = future;
    }

    @Override
    public Future getFuture() {
        return this.future;
    }
}
