package com.heyu.api.controller.certificate;

import com.heyu.api.baidu.handle.certificate.BFourFactorsVerificationHandle;
import com.heyu.api.baidu.request.certificate.BFourFactorsVerificationRequest;
import com.heyu.api.baidu.response.certificate.BFourFactorsVerificationResp;
import com.heyu.api.controller.BaseController;
import com.heyu.api.data.annotation.CacheResult;
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.resp.certificate.Factors4VerificationResp;
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;

/***
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1742614719901#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E5%8D%A1%E8%AF%81OCR&api=rest%2F2.0%2Focr%2Fv1%2Ffour_factors_verification&method=post
 *
 * 企业四要素核验
 *
 *
 * 接口描述
 * 比对校验企业名称、统一社会信用代码、法人姓名、注册证件号的一致性，验证企业工商信息。
 *
 * 注：目前支持工商注册的企业认证，事业单位、律师事务所等信息暂不支持验证，发生工商变更或刚注册的企业信息，预计在企业公示的核准日期T+15个工作日后可进行验证。
 *
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/factors4")
@NotIntercept
public class Factors4VerificationController extends BaseController {

    @Autowired
    private BFourFactorsVerificationHandle bFourFactorsVerificationHandle;


    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BFourFactorsVerificationRequest request) {
        Factors4VerificationResp resp = new Factors4VerificationResp();

        ApiR<BFourFactorsVerificationResp> bR = bFourFactorsVerificationHandle.handle(request);

        if (bR.isSuccess()) {
            BFourFactorsVerificationResp bFourFactorsVerificationResp = bR.getData();

            BFourFactorsVerificationResp.WordsResultDTO wordsResultDTO = bFourFactorsVerificationResp.getWordsResult();
            resp.setVerifyresult(wordsResultDTO.getVerifyresult());
            resp.setNamematch(wordsResultDTO.getNamematch());
            resp.setCompanymatch(wordsResultDTO.getCompanymatch());
            resp.setRegnummatch(wordsResultDTO.getRegnummatch());
            resp.setIdnummatch(wordsResultDTO.getIdnummatch());

            return R.ok().setData(resp);
        }


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


}
