package com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.hk;

import com.alibaba.fastjson2.JSON;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zws
 * @date 2024/9/3
 */

@Component
public class HkVideoMapper {

    @Value("${qxsd.hk.host}")
    private String host;
    @Value("${qxsd.hk.appKey}")
    private String appKey;
    @Value("${qxsd.hk.appSecret}")
    private String appSecret;

    /**
     * 根据indexcode获取播放流地址
     * @param cameraIndexCode
     * @return
     */
    public String getCameraPreviewURLs(String cameraIndexCode){
        ArtemisConfig.host = host;
        ArtemisConfig.appKey = appKey;
        ArtemisConfig.appSecret = appSecret;
        // 路径
        final Map<String, String> pathMap = new HashMap<>() {{
            put("https://", "/artemis/api/video/v1/cameras/previewURLs");
        }};

        //参数
        Map<String, Object> params = new HashMap<>() {{
            put("cameraIndexCode", cameraIndexCode);
            put("streamType", 0);
            put("protocol", "ws");
            put("transmode", 0);
            put("expand", "transcode=0");
        }};


        final String result = ArtemisHttpUtil.doPostBytesArtemis(pathMap,
                JSON.toJSONBytes(params),
                null,
                null, "application/json;charset=UTF-8");
        return result;
    }

    public String getPlaybackURLs(String cameraIndexCode,String beginTime,String endTime){
        ArtemisConfig.host = host;
        ArtemisConfig.appKey = appKey;
        ArtemisConfig.appSecret = appSecret;
        // 路径
        final Map<String, String> pathMap = new HashMap<>() {{
            put("https://", "/artemis/api/video/v1/cameras/playbackURLs");
        }};

        //参数
        Map<String, Object> params = new HashMap<>() {{
            put("cameraIndexCode", cameraIndexCode);
            put("beginTime", beginTime);
            put("endTime", endTime);
        }};


        final String result = ArtemisHttpUtil.doPostBytesArtemis(pathMap,
                JSON.toJSONBytes(params),
                null,
                null, "application/json;charset=UTF-8");
        return result;
    }


    public String getCameraIndexCode(String treeCode,String regionIndexCode){
        ArtemisConfig.host = host;
        ArtemisConfig.appKey = appKey;
        ArtemisConfig.appSecret = appSecret;
        // 路径
        final Map<String, String> pathMap = new HashMap<>() {{
            put("https://", "/artemis/api/resource/v3/cameras/getAllCamerasByUnitIndexCodes");
        }};

        //参数
        Map<String, Object> params = new HashMap<>() {{
            put("treeCode", treeCode);
            put("regionIndexCodes", regionIndexCode);

        }};


        final String result = ArtemisHttpUtil.doPostBytesArtemis(pathMap,
                JSON.toJSONBytes(params),
                null,
                null, "application/json;charset=UTF-8");
        return result;
    }


}
