package net.northking.cctp.se.util;

import com.alibaba.fastjson.JSON;
import net.northking.cctp.se.device.bean.DebuggerDeviceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;

import java.util.Map;

public class MobileUtil {

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

    private static final String SCREEN_SHOT_URL = "http://%s/engine/getScreenShot";

    public static String snapshot(String remoteAddress, String platform, Map<String, Object> initData) {
        DebuggerDeviceInfo info = new DebuggerDeviceInfo();
        info.setPlatform(platform);
        info.setDeviceId((String) initData.get("deviceId"));
        info.setLength((Integer) initData.get("width"));   //长
        info.setWidth((Integer) initData.get("height"));   //宽
        info.setResolution((String) initData.get("resolution"));
        info.setX((Integer) initData.get("x"));
        info.setY((Integer) initData.get("y"));
        info.setScreenLength((Integer) initData.get("screenWidth"));   //长
        info.setScreenWidth((Integer) initData.get("screenHeight"));   //宽
        info.setUserToken((String) initData.get("token"));  //用户FeignCctpConfigtoken
        info.setTaskId(initData.containsKey("taskId") && initData.get("taskId") != null  ? initData.get("taskId").toString() : null); //任务Id
        logger.info("参数：{}", JSON.toJSONString(info));
        HttpEntity<DebuggerDeviceInfo> entity = new HttpEntity<>(info);
        String result = null;
        try {
            result = HttpUtils.doPost(String.format(SCREEN_SHOT_URL, remoteAddress), entity, String.class);
        } catch (Exception e) {
            logger.error("截图失败",e);
        }
        return result;
    }
}
