package com.heyu.api.controller.certificate;


import com.heyu.api.baidu.handle.certificate.BMarriageCertificateHandle;
import com.heyu.api.baidu.request.certificate.BMarriageCertificateRequest;
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.MapUtils;
import com.heyu.api.data.utils.R;
import com.heyu.api.resp.certificate.MarriageCertificateResp;
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.Map;


/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740314877734#/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%2Fmarriage_certificate&method=post
 * <p>
 * <p>
 * 结婚证识别
 */


@Slf4j
@RestController
@RequestMapping("/marriage")
@NotIntercept
public class MarriageCertificateController extends BaseController {


    @Autowired
    private BMarriageCertificateHandle bMarriageCertificateHandle;


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

        ApiR<Map> bR = bMarriageCertificateHandle.handle(request);
        if (bR.isSuccess()) {
            Map<String, Object> data = bR.getData();
            resp.setManRealName(MapUtils.getByExpr(data, "words_result.姓名_男.word"));
            resp.setManRealNameConfidence(MapUtils.getByExpr(data, "words_result.姓名_男.probability"));

            resp.setManIdCard(MapUtils.getByExpr(data, "words_result.身份证件号_男.word"));
            resp.setManIdCardConfidence(MapUtils.getByExpr(data, "words_result.身份证件号_男.probability"));

            resp.setManBirthday(MapUtils.getByExpr(data, "words_result.出生日期_男.word"));
            resp.setManBirthdayConfidence(MapUtils.getByExpr(data, "words_result.出生日期_男.probability"));

            resp.setManNationality(MapUtils.getByExpr(data, "words_result.国籍_男.word"));
            resp.setManNationalityConfidence(MapUtils.getByExpr(data, "words_result.国籍_男.probability"));

            resp.setManGender(MapUtils.getByExpr(data, "words_result.性别_男.word"));
            resp.setManGenderConfidence(MapUtils.getByExpr(data, "words_result.性别_男.probability"));

            resp.setWomanRealName(MapUtils.getByExpr(data, "words_result.姓名_女.word"));
            resp.setWomanRealNameConfidence(MapUtils.getByExpr(data, "words_result.姓名_女.probability"));

            resp.setWomanIdCard(MapUtils.getByExpr(data, "words_result.身份证件号_女.word"));
            resp.setWomanIdCardConfidence(MapUtils.getByExpr(data, "words_result.身份证件号_女.probability"));

            resp.setWomanBirthday(MapUtils.getByExpr(data, "words_result.出生日期_女.word"));
            resp.setWomanBirthdayConfidence(MapUtils.getByExpr(data, "words_result.出生日期_女.probability"));

            resp.setWomanNationality(MapUtils.getByExpr(data, "words_result.国籍_女.word"));
            resp.setWomanNationalityConfidence(MapUtils.getByExpr(data, "words_result.国籍_女.probability"));

            resp.setWomanGender(MapUtils.getByExpr(data, "words_result.性别_女.word"));
            resp.setWomanGenderConfidence(MapUtils.getByExpr(data, "words_result.性别_女.probability"));

            resp.setRegisterDate(MapUtils.getByExpr(data, "words_result.登记日期.word"));
            resp.setRegisterDateConfidence(MapUtils.getByExpr(data, "words_result.登记日期.probability"));

            resp.setDivorceNumber(MapUtils.getByExpr(data, "words_result.结婚证字号.word"));
            resp.setDivorceNumberConfidence(MapUtils.getByExpr(data, "words_result.结婚证字号.probability"));

            resp.setHolderCertified(MapUtils.getByExpr(data, "words_result.持证人.word"));
            resp.setHolderCertifiedConfidence(MapUtils.getByExpr(data, "words_result.持证人.probability"));

            resp.setRemark(MapUtils.getByExpr(data, "words_result.备注.word"));
            resp.setRemarkConfidence(MapUtils.getByExpr(data, "words_result.备注.probability"));
            return R.ok().setData(resp);
        }
        return R.error();
    }


}
