package com.mortals.xhx.module.hik.camera.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.module.hik.AbstractHikService;
import com.mortals.xhx.module.hik.HikApiRest;
import com.mortals.xhx.module.hik.camera.model.req.CameraListReq;
import com.mortals.xhx.module.hik.camera.model.req.CameraReq;
import com.mortals.xhx.module.hik.camera.model.rsp.CameraDataInfo;
import com.mortals.xhx.module.hik.camera.model.rsp.CameraInfo;
import com.mortals.xhx.module.hik.camera.service.IHikCameraService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 海康视频接口类
 *
 * @author: zxfei
 * @date: 2023/4/12 17:51
 */
@Service("hikCameraService")
@Slf4j
public class HikCameraServiceImpl extends AbstractHikService implements IHikCameraService {


    @Override
    public Rest<CameraDataInfo> findCameraList(CameraListReq cameraListReq) {
        ArtemisConfig config = getArtemisConfig();
        String getCamsApi = ARTEMIS_PATH + "/api/resource/v1/camera/advance/cameraList";
        path.put(protocol, getCamsApi);
        try {
            log.info("camera list req=>{}", JSON.toJSONString(cameraListReq));
            String respJson = ArtemisHttpUtil.doPostStringArtemis(config, path, JSON.toJSONString(cameraListReq), null, null, "application/json");
            HikApiRest<CameraDataInfo> rest = JSON.parseObject(respJson, new TypeReference<HikApiRest<CameraDataInfo>>() {
            });
            if ("0".equals(rest.getCode())) {
                return Rest.ok(rest.getData());
            } else {
                log.info("camera list error resp=>{}", JSON.toJSONString(rest));
                return Rest.fail(rest.getMsg());
            }
        } catch (Exception e) {
            log.error("camera list error异常", e);
            return Rest.fail(e.getMessage());
        }
    }
}
