package com.heyu.api.controller.certificate;

import com.heyu.api.baidu.handle.certificate.BThreeFactorsVerificationHandle;
import com.heyu.api.baidu.request.certificate.BFourFactorsVerificationRequest;
import com.heyu.api.baidu.response.certificate.BThreeFactorsVerificationResp;
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.Factors3VerificationResp;
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=1742615758969#/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%2Fthree_factors_verification&method=post
 *
 * 企业三要素核验
 *
 *
 * 接口描述
 * 通过核验企业名称、统一社会信用代码、法人姓名一致性，快速核验企业资质。
 *
 * 注：目前支持工商注册的企业认证，事业单位、律师事务所等信息暂不支持验证，发生工商变更或刚注册的企业信息，预计在企业公示的核准日期T+3个工作日后可进行验证。
 *
 */
@Slf4j
@RestController
@RequestMapping("/factors3")
@NotIntercept
public class Factors3VerificationController extends BaseController {

    @Autowired
    private BThreeFactorsVerificationHandle bFourFactorsVerificationHandle;

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

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

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

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

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


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


}
