package net.northking.cctp.se.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.appium.java_client.AppiumDriver;
import net.northking.cctp.element.core.exception.EnvironmentException;
import net.northking.cctp.element.core.exception.ExecuteException;
import net.northking.cctp.se.device.bean.DebuggerDeviceInfo;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;

import java.net.URI;
import java.util.Map;

public class IosUtil extends PhoneUtil{

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

    private static final String ALL_SCREEN_SHOT_URL = "http://%s/engine/uploadShotAllScreen";


    public static Double getWindowsSize(AppiumDriver<WebElement> driver) {
        if (null == driver) {
            logger.error("driver获取为空");
            throw new EnvironmentException("设备自动化驱动连接已断开，请检查驱动程序是否正常");
        }
        Capabilities capabilities = driver.getCapabilities();
        //todo:这里后面确定wda的地址是多少
        String wdaUrl = (String) capabilities.getCapability("webDriverAgentUrl");
        String deviceId = (String) capabilities.getCapability("deviceName");
        String windowsUrl = wdaUrl + "/window/size";
        Double scale = 2.0;
        try {
            JSONObject object = HttpUtils.doGet(new URI(windowsUrl), JSONObject.class);
            JSONObject value = object.getJSONObject("value");
            scale = value.getDoubleValue("scale");
            logger.info("手机【{}】的宽高比例：{}",deviceId,scale);
            return scale;
        } catch (Exception e) {
            logger.error("获取手机【{}】宽高比例失败:{}",deviceId, e);
            throw new ExecuteException("获取手机宽高比例失败");
        }
    }







	





}
