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

import lombok.Getter;
import lombok.Setter;
import org.apache.seatunnel.api.configuration.Option;
import org.apache.seatunnel.api.configuration.Options;
import org.apache.seatunnel.api.configuration.ReadonlyConfig;
import org.apache.seatunnel.transform.coladd.ColAddEntity;
import org.apache.seatunnel.transform.coladd.ColAddTransformConfig;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class ScriptTransformConfig implements Serializable {

    public static final Option<List<ScriptField>> SCRIPT_FIELDS =
            Options.key("fields")
                    .listType(ScriptField.class)
                    .noDefaultValue()
                    .withDescription("Specify the fields");

    public static final Option<String> SCRIPT_CONTENT =
            Options.key("script_content")
                    .stringType()
                    .noDefaultValue()
                    .withDescription("Specify the scriptContent");

    private List<ScriptField> scriptFields = new ArrayList<>();
    private String scriptContent;

    public static ScriptTransformConfig of(ReadonlyConfig config) {
        ScriptTransformConfig scriptTransformConfig = new ScriptTransformConfig();
        scriptTransformConfig.setScriptFields(config.get(SCRIPT_FIELDS));
        scriptTransformConfig.setScriptContent(config.get(SCRIPT_CONTENT));
        return scriptTransformConfig;
    }
}
