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.camera.model.req.CameraListReq;
import com.mortals.xhx.module.hik.camera.model.rsp.CameraDataInfo;
import com.mortals.xhx.module.hik.camera.service.IHikCameraService;
import com.mortals.xhx.module.hik.face.model.rsp.plan.PlanRecognBlackInfo;
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<List<CameraDataInfo>> findCameraList(CameraListReq cameraListReq) {
        ArtemisConfig config = getArtemisConfig();
        String getCamsApi = ARTEMIS_PATH + "/api/resource/v1/cameras";
        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");
            log.info("camera list resp=>{}", respJson);
            Rest<List<CameraDataInfo>> rest = JSON.parseObject(respJson, new TypeReference<Rest<List<CameraDataInfo>>>() {
            });
            if (rest.getCode() == 0) {
                return Rest.ok(rest.getData());
            } else {
                return Rest.fail(rest.getMsg());
            }
        } catch (Exception e) {
            log.error("camera list error异常", e);
            return Rest.fail(e.getMessage());
        }
    }
}
