package com.heyu.api.controller.mobile;

import com.heyu.api.request.mobile.Mobile2MetaVerificationRequest;
import com.heyu.api.resp.mobile.MobileInfoVerificationResp;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.R;
import com.heyu.api.tencent.handle.TMinorsVerificationHandle;
import com.tencentcloudapi.faceid.v20180301.models.MinorsVerificationRequest;
import com.tencentcloudapi.faceid.v20180301.models.MinorsVerificationResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/***
 * 手机号实名查询
 */
@Slf4j
@RestController
@RequestMapping("/mobile/info")

@NotIntercept
public class MinorsVerificationController {


    public final static Map<String, String> checkResult = new HashMap<>();
    public final static Map<String, String> ageRangeMap = new HashMap<>();


    @Autowired
    private TMinorsVerificationHandle tMinorsVerificationHandle;

    @RequestMapping("/verification")
    public R verification(Mobile2MetaVerificationRequest request) {
        MobileInfoVerificationResp resp = new MobileInfoVerificationResp();
        MinorsVerificationRequest tPhone3MetaVerificationRequest = new MinorsVerificationRequest();
        tPhone3MetaVerificationRequest.setMobile(request.getMobile());
        // 0：使用手机号进行校验；
        tPhone3MetaVerificationRequest.setType("0");

        ApiR<MinorsVerificationResponse> tR = tMinorsVerificationHandle.handle(tPhone3MetaVerificationRequest);


        if (tR.isSuccess()) {
            MinorsVerificationResponse response = tR.getData();
            resp.setCheckResult(response.getResult());
            resp.setDesc(checkResult.get(response.getResult()));
            resp.setAgeRange(response.getAgeRange());
            resp.setAgeRangeDesc(ageRangeMap.get(response.getAgeRange()));
            return R.ok().setData(resp);

        }
        return R.error(tR.getErrorMsg());
    }


    static {
        checkResult.put("0:", "成年");
        checkResult.put("-1", "未成年");
        checkResult.put("-3", "姓名和身份证号不一致");
        checkResult.put("-2", "未查询到手机号信息");
        checkResult.put("-4", "非法身份证号（长度、校验位等不正确）");
        checkResult.put("-5", "非法姓名（长度、格式等不正确）");
        checkResult.put("-6", "权威数据源服务异常");
        checkResult.put("-7", "未查询到身份信息");

        ageRangeMap.put("[0,8)", "表示年龄小于8周岁区间，不包括8岁");
        ageRangeMap.put("[8,16)", "表示年龄8-16周岁区间，不包括16岁");
        ageRangeMap.put("[16,18)", "表示年龄16-18周岁区间，不包括18岁");
        ageRangeMap.put("[18,+)", "表示年龄大于18周岁");


    }

}
