package cn.iocoder.yudao.module.ocr.framework.ocr.config;

import cn.iocoder.yudao.module.ocr.framework.ocr.core.client.OcrClientFactory;
import cn.iocoder.yudao.module.ocr.framework.ocr.core.client.OcrClientFactoryImpl;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * OCR 自动配置类
 */
@AutoConfiguration
@EnableConfigurationProperties(OcrProperties.class)
public class OcrAutoConfiguration {

    @Bean
    public OcrClientFactory ocrClientFactory(OcrProperties properties) {
        OcrClientFactoryImpl factory = new OcrClientFactoryImpl(properties.getDefaultProvider());

        // 初始化百度客户端
        if (properties.getBaidu() != null) {
            factory.createOrUpdateClient("baidu", properties.getBaidu());
        }

        return factory;
    }

}
