package net.northking.cctp.upperComputer.driver.ios;

import net.northking.cctp.upperComputer.driver.usbmuxd.AppleDevice;
import net.northking.cctp.upperComputer.driver.usbmuxd.UsbMuxd;

import java.io.IOException;

public class LocalUsbmuxdDeviceSocketProvider implements DeviceSocketProvider {

    /**
     * 要连接的usbmuxd对象，需要提供对应设备的服务
     */
    private final UsbMuxd usbMuxd;

    /**
     * 要请求的设备
     */
    private final AppleDevice appleDevice;

    /**
     * 设备上WebDriverAgent程序监听的API端口，此端口接受HTTP请求
     */
    private final int wdaApiPort;

    public LocalUsbmuxdDeviceSocketProvider(UsbMuxd usbMuxd, AppleDevice appleDevice, int wdaApiPort) {
        this.usbMuxd = usbMuxd;
        this.appleDevice = appleDevice;
        this.wdaApiPort = wdaApiPort;
    }

    @Override
    public String getUdid() {
        return appleDevice.getSerial();
    }

    @Override
    public DeviceSocketStream createConnect() throws IOException {
        return new LocalUsbmuxdDeviceSocketStream(usbMuxd, appleDevice, wdaApiPort);
    }

    public UsbMuxd getUsbMuxd() {
        return usbMuxd;
    }

    public AppleDevice getAppleDevice() {
        return appleDevice;
    }

    public int getWdaApiPort() {
        return wdaApiPort;
    }
}
