/**
 * 
 */
package org.springblade.etl.connector.base;

import java.util.Optional;

import org.springblade.etl.entity.JobTask;
import org.springblade.etl.util.EtlJsonUtil;

import com.fasterxml.jackson.databind.node.ObjectNode;

/**
 * @author wookvn
 *
 */
public interface SeatunnelConnector<T extends SeatunnelConfig> {

	/**
	 * 构造Seatunnel配置
	 * @param configJson
	 * @return
	 */
	public T buildConfig(String configJson);
	/**
	 * 校验参数的正确性
	 * @param configJson
	 */
	public Object validate(String configJson);
	/**
	 * 准备工作 - transform不需要
	 * @param configJson
	 */
	default void prepare(String configJson) {}
	/**
	 * 构造Seatunnel配置
	 * @param jobTask
	 * @return
	 */
	default ObjectNode buildConfig(JobTask jobTask) {
		T seatunnelConfig = this.buildConfig(jobTask.getConfigJson());
		seatunnelConfig.setNodeId(Optional.<Integer>ofNullable(jobTask.getId()).orElse(0));
		seatunnelConfig.setPluginType(jobTask.getPluginType());
		seatunnelConfig.setPluginName(jobTask.getConnectorType().getPluginName());
		return EtlJsonUtil.toObjectNode(seatunnelConfig);
	}
}
