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>> findPlanRecognBlackList(CameraListReq cameraListReq) {
        ArtemisConfig config = getArtemisConfig();
        String getCamsApi = ARTEMIS_PATH + "/api/frs/v1/plan/recognition/black";
        path.put(protocol, getCamsApi);
        try {
            String respJson = ArtemisHttpUtil.doPostStringArtemis(config, path, JSON.toJSONString(cameraListReq), null, null, "application/json");
            Rest<List<CameraDataInfo>> rest = JSON.parseObject(respJson, new TypeReference<Rest<List<CameraDataInfo>>>() {
            });
            if (rest.getCode() == 0) {
                return Rest.ok(rest.getData());
            } else {
                log.info("camera list error resp=>", respJson);
                return Rest.fail(rest.getMsg());
            }
        } catch (Exception e) {
            log.error("camera list error异常", e);
            return Rest.fail(e.getMessage());
        }
    }
}
