package com.ltgk.video.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ltgk.common.utils.StringUtils;
import com.ltgk.common.utils.http.HttpUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @Author: zhouyaoyao
 * @Date 2025/2/25 16:45
 * Description: 通过 SDK 远程操作监控设备
 */
@Service
public class DsCameraService {

    /**
     * 获取监控设备 PTZ 配置链接
     */
    @Value("${sdk.hk.getPtzCfgUrl}")
    private String hkGetPtzCfgUrl;

    /**
     * 设置监控设备 PTZ 配置链接
     */
    @Value("${sdk.hk.setPtzCfgUrl}")
    private String hkSetPtzCfgUrl;

    /**
     * 订阅布防监控摄像头链接
     */
    @Value("${sdk.hk.setupAlarmChanUrl}")
    private String setupAlarmChanUrl;
    /**
     * 获取监控设备 PTZ 配置
     */
    public Object hkGetPtzCfg(String videoIp, String videoPort, String videoAccount, String videoPass) {

        String param = "videoIp="+videoIp+"&videoPort="+videoPort+"&videoAccount="+videoAccount+"&videoPass="+videoPass;
        String resultStr = HttpUtils.sendPost(hkGetPtzCfgUrl,param);
        if (StringUtils.isEmpty(resultStr)) {
            return null;
        }
        JSONObject resultObj = JSONObject.parseObject(resultStr);
        boolean success = resultObj.getBooleanValue("success");
        if (success) {
            return resultObj.getJSONObject("result");
        } else {
            return null;
        }
    }
    /**
     * 订阅布防监控摄像头
     */
    public Object setupAlarmChan(String videoIp, String videoPort, String videoAccount, String videoPass) {

        String param = "videoIp="+videoIp+"&videoPort="+videoPort+"&videoAccount="+videoAccount+"&videoPass="+videoPass;
        String resultStr = HttpUtils.sendPost(setupAlarmChanUrl,param);
        if (StringUtils.isEmpty(resultStr)) {
            return null;
        }
        JSONObject resultObj = JSONObject.parseObject(resultStr);
        boolean success = resultObj.getBooleanValue("success");
        if (success) {
            return resultObj.getJSONObject("result");
        } else {
            return null;
        }
    }

    /**
     * 设置监控设备 PTZ 配置
     */
    public boolean hkSetPtzCfg(String videoIp, String videoPort, String videoAccount, String videoPass, Integer pValue, Integer tValue, Integer zValue) {
        String param = "videoIp="+videoIp+"&videoPort="+videoPort+"&videoAccount="+videoAccount+"&videoPass="+videoPass+"&pValue="+pValue+"&tValue="+tValue+"&zValue="+zValue;
        String resultStr = HttpUtils.sendPost(hkSetPtzCfgUrl,param);
        if (StringUtils.isEmpty(resultStr)) {
            return false;
        }
        JSONObject resultObj = JSONObject.parseObject(resultStr);
        boolean success = resultObj.getBooleanValue("success");
        return success;
    }
}
