package com.heyu.api.controller.certificate;


import com.heyu.api.baidu.handle.certificate.BBirthCertificateHandle;
import com.heyu.api.baidu.request.certificate.BBirthCertificateRequest;
import com.heyu.api.baidu.response.certificate.BBirthCertificateResp;
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.request.certificate.BirthCertificateReq;
import com.heyu.api.resp.certificate.BirthCertificateResp;
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=1740309618781#/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%2Fbirth_certificate&method=post
 * <p>
 * <p>
 * 出生医学证明识别
 *
 *接口描述
 * 支持对出生医学证明的23个关键字段进行结构化识别，包括新生儿姓名、性别、出生时间、父亲姓名、母亲姓名、出生证编号等。
 *
 */
@Slf4j
@RestController
@RequestMapping("/birth")
@NotIntercept
public class BirthCertificateController extends BaseController {




    @Autowired
    private BBirthCertificateHandle birthCertificateHandle;

    @RequestMapping("/certificate")
    @CacheResult
    public R recognize(BirthCertificateReq request) {
        BirthCertificateResp resp = new BirthCertificateResp();

        BBirthCertificateRequest birthCertificateRequest = new BBirthCertificateRequest();
        birthCertificateRequest.setImageBase64(request.getImageBase64());
        birthCertificateRequest.setImageUrl(request.getImageUrl());

        ApiR<BBirthCertificateResp> bR = birthCertificateHandle.handle(birthCertificateRequest);
        if(bR.isSuccess()){
            BBirthCertificateResp bBirthCertificateResp =   bR.getData();
            BBirthCertificateResp.WordsResultDTO wordsResultDTO = bBirthCertificateResp.getWordsResult();
            resp.setBirthProvince(wordsResultDTO.getBirthProvince().getWords());
            resp.setBirthWeight(wordsResultDTO.getBirthWeight().getWords());
            resp.setMotherNationality(wordsResultDTO.getMotherNationality().getWords());
            resp.setFatherAddress(wordsResultDTO.getFatherAddress().getWords());
            resp.setMotherEthnic(wordsResultDTO.getMotherEthnic().getWords());
            resp.setMotherAddress(wordsResultDTO.getMotherAddress().getWords());
            resp.setCode(wordsResultDTO.getCode().getWords());
            resp.setBabySex(wordsResultDTO.getBabySex().getWords());
            resp.setBirthCity(wordsResultDTO.getBirthCity().getWords());
            resp.setBabyBirthday(wordsResultDTO.getBabyBirthday().getWords());
            resp.setBabyName(wordsResultDTO.getBabyName().getWords());
            resp.setFatherAge(wordsResultDTO.getFatherAge().getWords());
            resp.setFatherEthnic(wordsResultDTO.getFatherEthnic().getWords());
            resp.setMotherName(wordsResultDTO.getMotherName().getWords());
            resp.setMotherIdNumber(wordsResultDTO.getMotherID().getWords());
            resp.setBirthLength(wordsResultDTO.getBirthLength().getWords());
            resp.setGestationalAge(wordsResultDTO.getGestationalAge().getWords());
            resp.setBirthCity(wordsResultDTO.getBirthCity().getWords());
            resp.setMotherAge(wordsResultDTO.getMotherAge().getWords());
            resp.setHospital(wordsResultDTO.getHospital().getWords());
            resp.setFatherNationality(wordsResultDTO.getFatherNationality().getWords());
            resp.setFatherIdNumber(wordsResultDTO.getFatherID().getWords());
            resp.setFatherName(wordsResultDTO.getFatherName().getWords());
            return R.ok().setData(resp);
        }
        return R.error(bR.getErrorMsg());

    }


}
