package cn.iocoder.yudao.module.ocr.framework.ocr.core.client.impl;

import cn.iocoder.yudao.module.ocr.framework.ocr.core.result.VehicleLicenseResult;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * 百度 OCR 本地测试
 */
@Slf4j
public class BaiduOcrClientLocalTest {

    public static void main(String[] args) throws IOException {
        // 配置百度 OCR
        BaiduOcrClientConfig config = new BaiduOcrClientConfig();
        config.setAppId("7506572");
        config.setApiKey("wnQhaotHBbq9LRf8LbuNDNiK");
        config.setSecretKey("wzORcuENPSwBJxh0zrUwH1s05tA9vEfq");

        // 创建客户端
        BaiduOcrClient client = new BaiduOcrClient(config);
        client.init();

        log.info("百度 OCR 客户端初始化成功");

        // 读取测试图片
        String imagePath = "/Users/kkfluous/Projects/ai-coding/ln-oneos/ext/a55d670c0f36be8f8a0f713c3fcd4091.jpg";
        byte[] imageData = Files.readAllBytes(Paths.get(imagePath));
        log.info("读取图片成功，大小：{} bytes", imageData.length);

        // 执行识别
        log.info("开始识别行驶证...");
        long startTime = System.currentTimeMillis();

        try {
            VehicleLicenseResult result = client.recognizeVehicleLicense(imageData);
            long costTime = System.currentTimeMillis() - startTime;

            log.info("识别成功！耗时：{} ms", costTime);
            log.info("========== 识别结果 ==========");
            log.info("车辆识别代号（VIN）: {}", result.getVin());
            log.info("号牌号码: {}", result.getPlateNo());
            log.info("品牌型号: {}", result.getBrand());
            log.info("车辆类型: {}", result.getVehicleType());
            log.info("所有人: {}", result.getOwner());
            log.info("使用性质: {}", result.getUseCharacter());
            log.info("发动机号码: {}", result.getEngineNo());
            log.info("注册日期: {}", result.getRegisterDate());
            log.info("发证日期: {}", result.getIssueDate());
            log.info("检验记录: {}", result.getInspectionRecord());
            log.info("强制报废期止: {}", result.getScrapDate());
            log.info("整备质量: {}", result.getCurbWeight());
            log.info("总质量: {}", result.getTotalMass());
            log.info("核定载人数: {}", result.getApprovedPassengerCapacity());
            log.info("==============================");

        } catch (Exception e) {
            log.error("识别失败", e);
        }
    }

}
