
package cn.orionsec.ops;

import cn.orionsec.kit.lang.support.Attempt;
import cn.orionsec.kit.lang.utils.reflect.PackageScanner;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MappingConversionProvider implements InitializingBean {

    private final String CONVERSION_PACKAGE = this.getClass().getPackage().getName() + ".mapping.*";

    private static final String EXPORTER_PACKAGE = "cn.orionsec.ops.entity.exporter";

    private static final String IMPORTER_PACKAGE = "cn.orionsec.ops.entity.importer";

    @Override
    public void afterPropertiesSet() throws Exception {
        new PackageScanner(CONVERSION_PACKAGE, EXPORTER_PACKAGE, IMPORTER_PACKAGE)
                .with(MappingConversionProvider.class)
                .with(DataModuleConversionProvider.class)
                .scan()
                .getClasses()
                .forEach(Attempt.rethrows(s -> {
                    log.info("register type conversion {}", s.getName());
                    Class.forName(s.getName());
                }));
    }

}
