package com.heyu.api.controller.mobile;


import com.heyu.api.resp.mobile.MobileNetworkTimeVerificationResp;
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.TMobileNetworkTimeVerificationHandle;
import com.heyu.api.tencent.request.TMobileNetworkTimeVerificationRequest;
import com.tencentcloudapi.faceid.v20180301.models.MobileNetworkTimeVerificationResponse;
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/network/time")
@NotIntercept
public class   MobileNetworkTimeVerificationController {


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


    @Autowired
    private TMobileNetworkTimeVerificationHandle mobileNetworkTimeVerificationHandle;

    @RequestMapping("/verification")
    public R recognize(TMobileNetworkTimeVerificationRequest request) {
        MobileNetworkTimeVerificationResp resp = new MobileNetworkTimeVerificationResp();
        resp.setCheckResult("-1");
        ApiR<MobileNetworkTimeVerificationResponse> aR = mobileNetworkTimeVerificationHandle.handle(request);
        if (aR.isSuccess()) {
            MobileNetworkTimeVerificationResponse response = aR.getData();
            String result = response.getResult();
            resp.setCheckResult(result);
            resp.setCheckResultDesc(checkResult.get(result));
            resp.setDesc(response.getDescription());
            resp.setNetworkRangeTime(response.getRange());
            return R.ok().setData(resp);
        }
        return R.error(aR.getErrorMsg());
    }






    static {
        checkResult.put("-1", "失败");
        checkResult.put("0", "成功");
        checkResult.put("-2", "手机号不存在");
        checkResult.put("-3", "手机号存在，但无法查询到在网时长");
        checkResult.put("-1", "手机号格式不正确");
        checkResult.put("-4", "验证中心服务繁忙");
        checkResult.put("-5", "认证次数超过当日限制，请次日重试");
    }
}
