package cn.iocoder.yudao.module.ocr.service.ocr;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.ocr.framework.ocr.core.client.OcrClient;
import cn.iocoder.yudao.module.ocr.framework.ocr.core.client.OcrClientFactory;
import cn.iocoder.yudao.module.ocr.framework.ocr.core.result.VehicleLicenseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * OCR 服务实现类
 */
@Service
@Slf4j
public class OcrServiceImpl implements OcrService {

    @Resource
    private OcrClientFactory ocrClientFactory;

    @Override
    public VehicleLicenseResult recognizeVehicleLicense(byte[] imageData) {
        // 使用默认厂商
        OcrClient client = ocrClientFactory.getDefaultClient();
        return client.recognizeVehicleLicense(imageData);
    }

    @Override
    public VehicleLicenseResult recognizeVehicleLicense(byte[] imageData, String provider) {
        // 使用指定厂商
        OcrClient client = StrUtil.isNotBlank(provider)
                ? ocrClientFactory.getClient(provider)
                : ocrClientFactory.getDefaultClient();
        return client.recognizeVehicleLicense(imageData);
    }

}
