package org.apache.seatunnel.transform.script.java;

import com.google.auto.service.AutoService;
import org.apache.seatunnel.api.configuration.util.OptionRule;
import org.apache.seatunnel.api.table.catalog.CatalogTable;
import org.apache.seatunnel.api.table.connector.TableTransform;
import org.apache.seatunnel.api.table.factory.Factory;
import org.apache.seatunnel.api.table.factory.TableFactoryContext;
import org.apache.seatunnel.api.table.factory.TableTransformFactory;
import org.apache.seatunnel.transform.script.common.ScriptTransformConfig;

@AutoService(Factory.class)
public class JavaScriptTransformFactory implements TableTransformFactory {

    @Override
    public String factoryIdentifier() {
        return JavaScriptTransform.PLUGIN_NAME;
    }

    @Override
    public OptionRule optionRule() {
        return OptionRule.builder()
                .required(
                        ScriptTransformConfig.SCRIPT_CONTENT,
                        ScriptTransformConfig.SCRIPT_FIELDS
                ).build();
    }

    @Override
    public TableTransform createTransform(TableFactoryContext context) {
        CatalogTable catalogTable = context.getCatalogTable();
        return () -> new JavaScriptTransform(context.getOptions(), catalogTable);
    }
}
