package cn.gov.customs.wxjy.common.importtool.config;


import cn.gov.customs.wxjy.common.importtool.core.interfaces.DataProcessor;
import cn.gov.customs.wxjy.common.importtool.core.interfaces.ImportDataConverter;
import cn.gov.customs.wxjy.common.importtool.core.interfaces.ImportDataValidator;
import cn.gov.customs.wxjy.common.importtool.core.interfaces.UniqueKeyGenerator;

import java.util.List;

public class ImportConfigBuilder<S, T> {
	private final ImportConfig<S, T> config = new ImportConfig<>();

	public ImportConfigBuilder<S, T> converter(ImportDataConverter<S, T> converter) {
		config.setConverter(converter);
		return this;
	}

	public ImportConfigBuilder<S, T> validator(ImportDataValidator<T> validator) {
		config.setValidator(validator);
		return this;
	}

	public ImportConfigBuilder<S, T> uniqueKeyGenerator(UniqueKeyGenerator<T> uniqueKeyGenerator) {
		config.setUniqueKeyGenerator(uniqueKeyGenerator);
		return this;
	}

	public ImportConfigBuilder<S, T> dataProcessor(DataProcessor<T> dataProcessor) {
		config.setDataProcessor(dataProcessor);
		return this;
	}

	public ImportConfigBuilder<S, T> skipExisting(boolean skipExisting) {
		config.setSkipExisting(skipExisting);
		return this;
	}

	public ImportConfigBuilder<S, T> batchSize(int batchSize) {
		config.setBatchSize(batchSize);
		return this;
	}

	// 新增 dataPreProcessor 方法
	public ImportConfigBuilder<S, T> dataPreProcessor(ImportConfig.DataPreProcessor<T> dataPreProcessor) {
		config.setDataPreProcessor(dataPreProcessor);
		return this;
	}

	// 新增 updater 方法（如果也需要的话）
	public ImportConfigBuilder<S, T> updater(ImportConfig.DataUpdater<T> updater) {
		config.setUpdater(updater);
		return this;
	}

	// 新增 updateFields 方法（如果也需要的话）
	public ImportConfigBuilder<S, T> updateFields(List<String> updateFields) {
		config.setUpdateFields(updateFields);
		return this;
	}


	public ImportConfig<S, T> build() {
		// 构建时自动验证配置
		config.validateConfig();
		return config;
	}

}
