package com.heyu.api.controller.certificate;


import com.heyu.api.baidu.handle.certificate.BBouseholdRegisterHandle;
import com.heyu.api.baidu.request.certificate.BBouseholdRegisterRequest;
import com.heyu.api.baidu.response.certificate.BBouseholdRegisterResp;
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.BouseholdRegisterReq;
import com.heyu.api.resp.certificate.BouseholdRegisterResp;
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=1740309163756#/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%2Fhousehold_register&method=post
 * <p>
 * <p>
 * 户口本识别
 * <p>
 * 接口描述
 * 支持对户口本内常住人口登记卡的全部 22 个字段，包括户号、姓名、与户主关系、性别、出生地、民族、出生日期、身份证号、本市县其他住址、曾用名、籍贯、宗教信仰、身高、血型、文化程度、婚姻状况、兵役状况、服务处所、职业、何时由何地迁往本市、何时由何地迁往本址、登记日期。
 * <p>
 * 支持对户口本内户主页的5个字段进行结构化识别，包括户别、户主姓名、户号、住址、户主页时间。
 */
@Slf4j
@RestController
@RequestMapping("/bousehold")
@NotIntercept
public class BouseholdRegisterController {


    @Autowired
    private BBouseholdRegisterHandle bBouseholdRegisterHandle;


    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BouseholdRegisterReq request) {

        BouseholdRegisterResp resp = new BouseholdRegisterResp();
        BBouseholdRegisterRequest bBouseholdRegisterRequest = new BBouseholdRegisterRequest();
        bBouseholdRegisterRequest.setHouseholdRegisterSide(request.getHouseholdRegisterSide());
        bBouseholdRegisterRequest.setImageBase64(request.getImageBase64());
        bBouseholdRegisterRequest.setImageUrl(request.getImageUrl());

        ApiR<BBouseholdRegisterResp> bR = bBouseholdRegisterHandle.handle(bBouseholdRegisterRequest);
        if (bR.isSuccess()) {

            BBouseholdRegisterResp bBouseholdRegisterResp = bR.getData();

            BBouseholdRegisterResp.WordsResultDTO wordsResultDTO = bBouseholdRegisterResp.getWordsResult();

            resp.setNation(wordsResultDTO.getNation().getWords());
            resp.setSex(wordsResultDTO.getSex().getWords());
            resp.setBirthday(wordsResultDTO.getBirthday().getWords());
            resp.setDate(wordsResultDTO.getDate().getWords());
            resp.setBirthAddress(wordsResultDTO.getBirthAddress().getWords());
            resp.setName(wordsResultDTO.getName().getWords());
            resp.setFormerName(wordsResultDTO.getFormerName().getWords());
            resp.setHouseholdNum(wordsResultDTO.getHouseholdNum().getWords());
            resp.setWWToCity(wordsResultDTO.getWWToCity().getWords());
            resp.setWWHere(wordsResultDTO.getWWHere().getWords());
            resp.setCardNo(wordsResultDTO.getCardNo().getWords());
            resp.setEducation(wordsResultDTO.getEducation().getWords());
            resp.setRelationship(wordsResultDTO.getRelationship().getWords());
            resp.setHeight(wordsResultDTO.getHeight().getWords());
            resp.setCareer(wordsResultDTO.getCareer().getWords());
            resp.setWorkAddress(wordsResultDTO.getWorkAddress().getWords());
            resp.setHometown(wordsResultDTO.getHometown().getWords());
            resp.setOtherAddress(wordsResultDTO.getOtherAddress().getWords());
            resp.setOtherAddress(wordsResultDTO.getOtherAddress().getWords());
            resp.setBelief(wordsResultDTO.getBelief().getWords());
            resp.setBloodType(wordsResultDTO.getBloodType().getWords());
            resp.setMaritalStatus(wordsResultDTO.getMaritalStatus().getWords());
            resp.setVeteranStatus(wordsResultDTO.getVeteranStatus().getWords());

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

        }

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