package com.yuchen.saas.park.service.util;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yuchen.saas.integration.feign.api.util.HikApiUtil;
import com.yuchen.saas.park.api.entity.park.PmgBatParkPeople;
import com.yuchen.saas.park.api.entity.park.PmgBatParkVisitor;
import com.yuchen.saas.park.api.entity.park.PmgBtnPeopleHik;
import com.yuchen.saas.park.service.util.iot.client.ResourceUtils;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;

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

public class HikUtils {

    // 园区人脸操作
    public Map<String, Object> parkPeopleHikMethod(PmgBatParkPeople pmgBatParkPeople,
                                                   PmgBtnPeopleHik pmgBtnPeopleHik,
                                                   String indexCode, String certificateType,
                                                   String faceBinaryData, String apiName) {
        R<Map<String, Object>> respData = null;
        // 定义新增人脸集合
        Map<String, Object> addFace = new HashMap<String, Object>();
        addFace.put("faceGroupIndexCode", indexCode); // 人脸分组ID
        // 人员信息变量
        Map<String, Object> faceInfo = new HashMap<String, Object>();
        faceInfo.put("name", pmgBatParkPeople.getId());
        faceInfo.put("sex", "男".equals(pmgBatParkPeople.getSex())?"1":"2");
        faceInfo.put("certificateType", certificateType); // 身份证
        faceInfo.put("certificateNum", pmgBatParkPeople.getIdCard());
        addFace.put("faceInfo", faceInfo);
        // 人脸图片信息
        Map<String, Object> facePic = new HashMap<String, Object>();
        facePic.put("faceBinaryData", faceBinaryData);

        addFace.put("facePic", facePic);

        // 通过用户id 查询头像与hik人脸库关联信息
        LambdaQueryWrapper<PmgBtnPeopleHik> peopleHikWrapper = Wrappers.lambdaQuery();

        // 封装人脸唯一标识集合、hik人脸关联信息ID集合
        if(Func.isNotEmpty(pmgBtnPeopleHik)) {
            addFace.put("indexCode", pmgBtnPeopleHik.getIndexCode());
        }
        Map<String, Object> reqMap = new HashMap<String, Object>();
        reqMap.put("body", addFace);
        reqMap.put("requestApi", apiName);
        return reqMap;
    }
    // 访客操作
    public Map<String, Object> parkVisitorHikMethod(PmgBatParkVisitor userInfo,
                                                    String indexCode,
                                                    String certificateType,
                                                    String faceBinaryData,
                                                    String apiName) {

        Map<String, Object> addFace = new HashMap<String, Object>();
        addFace.put("faceGroupIndexCode", indexCode); // 人脸分组ID
        // 人员信息变量
        Map<String, Object> faceInfo = new HashMap<String, Object>();
        faceInfo.put("name", userInfo.getId());
        faceInfo.put("sex", "2");
        faceInfo.put("certificateType", ResourceUtils.SHEN_FEN); // 身份证
        faceInfo.put("certificateNum", "身份证号");
        addFace.put("faceInfo", faceInfo);
        // 人脸图片信息
        Map<String, Object> facePic = new HashMap<String, Object>();
        facePic.put("faceBinaryData", PicToBase64Utils.imageChangeBase64(userInfo.getFaceImg()));

        addFace.put("facePic", facePic);

        Map<String, Object> reqMap = new HashMap<String, Object>();
        reqMap.put("body", addFace);
        reqMap.put("requestApi", HikApiUtil.ADD_FACE);

        return reqMap;
    }

}
