package fi.helsinki.cs.tmc.cli.tmcstuff;

import fi.helsinki.cs.tmc.core.configuration.TmcSettings;
import fi.helsinki.cs.tmc.core.domain.Course;

import com.google.common.base.Optional;

import org.apache.http.impl.conn.SystemDefaultRoutePlanner;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;

public class Settings implements TmcSettings {

    private String serverAddress;
    private String username;
    private String password;

    public Settings(String serverAddress, String username, String password) {
        this.serverAddress = serverAddress;
        this.username = username;
        this.password = password;
    }

    @Override
    public String getServerAddress() {
        return serverAddress;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean userDataExists() {
        return false;
    }

    @Override
    public Optional<Course> getCurrentCourse() {
        return Optional.absent();
    }

    @Override
    public String apiVersion() {
        return "7";
    }

    @Override
    public String clientName() {
        return "tmc-cli";
    }

    @Override
    public String clientVersion() {
        return "0.1.0";
    }

    @Override
    public String getFormattedUserData() {
        return null;
    }

    @Override
    public Path getTmcProjectDirectory() {
        return Paths.get("/tmp/tmc-cli");
    }

    @Override
    public Locale getLocale() {
        return new Locale("EN");
    }

    @Override
    public SystemDefaultRoutePlanner proxy() {
        return null;
    }

    @Override
    public Path getConfigRoot() {
        return getTmcProjectDirectory();
    }

    @Override
    public void setCourse(Course course) {
    }

    @Override
    public void setConfigRoot(Path path) {
    }

}

@@ -653,32 +653,572 @@
 assword;%0A    %7D%0A%0A
+    public Settings() %7B%0A        this.serverAddress = System.getenv(%22TMC_SERVER_ADDRESS%22);%0A        this.username = System.getenv(%22TMC_USERNAME%22);%0A        this.password = System.getenv(%22TMC_PASSWORD%22);%0A%0A        if (this.serverAddress == null %7C%7C this.username == null%0A                %7C%7C this.password == null) %7B%0A            String msg = %22Env variables for tmc-cli Settings are missing!%22%0A                    + %22%5CnTMC_SERVER_ADDRESS, TMC_USERNAME, TMC_PASSWORD%22;%0A            System.out.println(msg);%0A            System.exit(1);%0A        %7D%0A    %7D%0A%0A
     @Override%0A  

Read username and password from env variables