package org.implab.gradle.common.exec.runtime;

import java.io.File;
import java.util.Map;
import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.implab.gradle.common.exec.model.EnvironmentSpec;

@NonNullByDefault
public interface EnvironmentBuilder {
    /** Sets the specified environment variable */
    EnvironmentBuilder putEnvironment(String envVar, String value);

    /** Replaces environment with the supplied one */
    EnvironmentBuilder environment(Map<String, ? extends String> env);

    /**
     * Enables or disables environment inheritance for the child process
     */
    EnvironmentBuilder inheritEnvironment(boolean inherit);

    /** Specifies the working directory */
    EnvironmentBuilder workingDirectory(File directory);

    /** Specifies the working directory */
    EnvironmentBuilder workingDirectory(Optional<? extends File> directory);

    /** Copies the supplied environment to this one */
    default EnvironmentBuilder from(EnvironmentSpec environmentSpec) {
        return environment(environmentSpec.environment())
            .workingDirectory(environmentSpec.workingDirectory());
    }
}
