package com.braintreegateway;

import java.util.Arrays;

/**
 * Indicates the environment of the Braintree Gateway with which to interact.
 */
public enum Environment {
    /** For Braintree internal development. */
    DEVELOPMENT(developmentHost() + ":" + developmentPort(), developmentCertificates()),

    /** For production. */
    PRODUCTION("https://www.braintreegateway.com:443", new String[] {"ssl/www_braintreegateway_com.ca.der", "ssl/securetrust.ca.der"}),

    /** For merchant's to use during their development and testing. */
    SANDBOX("https://sandbox.braintreegateway.com:443", new String[] {"ssl/sandbox-godaddy-root.ca.der", "ssl/sandbox_braintreegateway_com.ca.der", "ssl/sandbox-godaddy-intermediate.ca.der"});

    public final String baseURL;
    public final String[] certificateFilenames;

    private Environment(String baseURL, String[] certificateFilenames) {
        this.baseURL = baseURL;
        this.certificateFilenames = Arrays.copyOf(certificateFilenames, certificateFilenames.length);
    }

    private static String developmentPort() {
        if (System.getenv().get("GATEWAY_PORT") != null) {
            return System.getenv().get("GATEWAY_PORT");
        } else if (System.getProperty("com.braintreegateway.port") != null) {
            return System.getProperty("com.braintreegateway.port");
        } else {
            return "3000";
        }
    }

    private static String developmentHost() {
        return System.getProperty("com.braintreegateway.host") == null ? "http://localhost" : System.getProperty("com.braintreegateway.host");
    }

    private static String[] developmentCertificates() {
        if (System.getProperty("com.braintreegateway.certificates") == null) {
            return new String[] {};
        } else {
            String certs = System.getProperty("com.braintreegateway.certificates");
            return certs.split(",");
        }
    }
}

@@ -147,12 +147,13 @@
 lic 
-enum
+class
  Env
@@ -218,135 +218,205 @@
     
-DEVELOPMENT(developmentHost() + %22:%22 + developmentPort(), developmentCertificates()),%0A%0A    /** For production. */%0A    PRODUCTION
+public static final Environment DEVELOPMENT = new Environment(%22http://localhost:3000%22, new String%5B%5D %7B%7D);%0A%0A    /** For production. */%0A    public static final Environment PRODUCTION = new Environment
 (%22ht
@@ -531,17 +531,17 @@
 a.der%22%7D)
-,
+;
 %0A%0A    /*
@@ -613,15 +613,65 @@
     
-SANDBOX
+public static final Environment SANDBOX = new Environment
 (%22ht
@@ -936,22 +936,21 @@
 ;%0A%0A    p
-rivate
+ublic
  Environ
@@ -1146,897 +1146,7 @@
    %7D
-%0A%0A    private static String developmentPort() %7B%0A        if (System.getenv().get(%22GATEWAY_PORT%22) != null) %7B%0A            return System.getenv().get(%22GATEWAY_PORT%22);%0A        %7D else if (System.getProperty(%22com.braintreegateway.port%22) != null) %7B%0A            return System.getProperty(%22com.braintreegateway.port%22);%0A        %7D else %7B%0A            return %223000%22;%0A        %7D%0A    %7D%0A%0A    private static String developmentHost() %7B%0A        return System.getProperty(%22com.braintreegateway.host%22) == null ? %22http://localhost%22 : System.getProperty(%22com.braintreegateway.host%22);%0A    %7D%0A%0A    private static String%5B%5D developmentCertificates() %7B%0A        if (System.getProperty(%22com.braintreegateway.certificates%22) == null) %7B%0A            return new String%5B%5D %7B%7D;%0A        %7D else %7B%0A            String certs = System.getProperty(%22com.braintreegateway.certificates%22);%0A            return certs.split(%22,%22);%0A        %7D%0A    %7D
 %0A%7D%0A

Make Environment a class so Joerg can instantiate it with QA values