package com.heyu.api.controller.mobile;


import com.heyu.api.resp.mobile.MobileStatusVerificationResp;
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.TMobileStatusHandle;
import com.heyu.api.tencent.request.TMobileStatusRequest;
import com.tencentcloudapi.faceid.v20180301.models.MobileStatusResponse;
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/status")
@NotIntercept
public class MobileStatusVerificationController {


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


    @Autowired
    private TMobileStatusHandle tMobileStatusHandle;

    @RequestMapping("/verification")
    public R recognize(TMobileStatusRequest request) {
        MobileStatusVerificationResp resp = new MobileStatusVerificationResp();
        ApiR<MobileStatusResponse> tR = tMobileStatusHandle.handle(request);
        if (tR.isSuccess()) {
            MobileStatusResponse response = tR.getData();
            resp.setCheckResult(response.getResult());
            resp.setDesc(checkResult.get(response.getResult()));
            resp.setReason(response.getDescription());
            resp.setStatusCode(response.getStatusCode());
            resp.setStatusCodeDesc(statusCodeMapDesc.get(response.getStatusCode()));
            return R.ok().setData(resp);
        }
        return R.error(tR.getErrorMsg());
    }


    static {
        checkResult.put("0", "成功");
        checkResult.put("-1", "未查询到结果");
        checkResult.put("-2", "手机号格式不正确");
        checkResult.put("-3", "验证中心服务繁忙");
        checkResult.put("-4", "认证次数超过当日限制，请次日重试");

        statusCodeMapDesc.put("0", "正常");
        statusCodeMapDesc.put("1", "停机");
        statusCodeMapDesc.put("2", "销号");
        statusCodeMapDesc.put("4", "不在网");
        statusCodeMapDesc.put("99", "未知状态");

    }
}
