package com.heyu.api.controller.traffic;


import com.heyu.api.baidu.handle.traffic.BVehicleRegistrationCertificateHandle;
import com.heyu.api.baidu.request.traffic.BVehicleRegistrationCertificateRequest;
import com.heyu.api.baidu.response.traffic.BVehicleRegistrationCertificateResp;
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.traffic.VehicleRegistrationCertificateResp;
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/?_=1740411162437&timestamp=1740412165257#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E4%BA%A4%E9%80%9A%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fvehicle_registration_certificate&method=post
 * <p>
 * <p>
 * 机动车登记证书识别
 * <p>
 * 接口描述
 * 支持对机动车登记证书的15个关键字段进行结构化识别，包括编号、机动车所有人、登记机关、登记日期、登记编号、车辆类型等，同时支持检测发证机关章
 */
@Slf4j
@RestController
@RequestMapping("/vehicle/registration/certificate")
@NotIntercept
public class VehicleRegistrationCertificateController extends BaseController {


    @Autowired
    private BVehicleRegistrationCertificateHandle bVehicleRegistrationCertificateHandle;


    @RequestMapping("/recognize")
    @CacheResult
    public R recognize(BVehicleRegistrationCertificateRequest request) {
        VehicleRegistrationCertificateResp resp = new VehicleRegistrationCertificateResp();
        ApiR<BVehicleRegistrationCertificateResp> bR = bVehicleRegistrationCertificateHandle.handle(request);

        if (bR.isSuccess()) {
            BVehicleRegistrationCertificateResp bVehicleRegistrationCertificateResp = bR.getData();
            BVehicleRegistrationCertificateResp.WordsResultDTO wordsResultDTO = bVehicleRegistrationCertificateResp.getWordsResult();

            resp.setRegistrationAuthority(wordsResultDTO.getRegistrationAuthority().getWords());   //登记机关
            resp.setVehicleModel(wordsResultDTO.getVehicleModel().getWords()); //车辆型号
            resp.setVehicleType(wordsResultDTO.getVehicleType().getWords()); //车辆类型
            resp.setRegistrationNum(wordsResultDTO.getRegistrationNum().getWords()); // 机动车登记编号
            resp.setEngineNum(wordsResultDTO.getEngineNum().getWords()); //发动机号
            resp.setNumber(wordsResultDTO.getNumber().getWords());        //编号
            resp.setBodyColor(wordsResultDTO.getBodyColor().getWords()); //	车身颜色
            resp.setRegistrationDate(wordsResultDTO.getRegistrationDate().getWords()); // 登记日期
            resp.setDateOfProduction(wordsResultDTO.getDateOfProduction().getWords()); // 出厂日期
            resp.setSeatingCapacity(wordsResultDTO.getSeatingCapacity().getWords()); // 核定载客
            resp.setDateOfIssue(wordsResultDTO.getDateOfIssue().getWords()); // 发证日期
            resp.setNatureOfUse(wordsResultDTO.getNatureOfUse().getWords()); // 使用性质
            resp.setVin(wordsResultDTO.getVin().getWords()); // 车架号
            resp.setSealOfIssueAuthority(wordsResultDTO.getSealOfIssueAuthority().getWords()); // 发证机关章，1表示有，0表示无
            resp.setNameIdcardNo(wordsResultDTO.getNameIdcardNo().getWords()); // 机动车所有人/身份证明名称/号码
            return R.ok().setData(resp);
        }

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