package se.arbetsformedlingen.venice.common;

import java.util.*;

public class Application {
    private String application;
    private List<Environment> environments;

    private static Map<String, String> probeNames;
    private static Map<String, String> ports;

    public Application(String application) {
        this.application = application;
        this.environments = new ArrayList<>();

        addPorts();
        addProbes();
    }

    private void addPorts() {
        if (ports == null) {
            ports = new HashMap<>();

            ports.put("gfr", "/wildfly05");
            ports.put("geo", "/wildfly01");
            ports.put("cpr", "/wildfly05");
            ports.put("marknadsanalys", "/wildfly02");
        }
    }

    private void addProbes() {
        if (probeNames == null) {
            probeNames = new HashMap<>();

            probeNames.put("gfr", "UgkForetagProbe");
            probeNames.put("geo", "UgkGeoProbe");
            probeNames.put("cpr", "CprProbe");
            probeNames.put("marknadsanalys", "MarknadsanalysProbe");
        }
    }

    void addEnvironment(Environment env) {
        this.environments.add(env);
    }

    public List<Environment> getEnvironments() {
        return environments;
    }

    public List<Host> getHosts() {
        List<Host> hosts = new LinkedList<>();
        for (Environment env : getEnvironments()) {
            hosts.addAll(env.getHosts());
        }

        return hosts;
    }

    public String getProbeName() {
        return probeNames.get(application);
    }

    public String getPort() {
        return ports.get(application);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Application that = (Application) o;
        return Objects.equals(application, that.application);
    }

    @Override
    public int hashCode() {
        return Objects.hash(application);
    }

    @Override
    public String toString() {
        return application;
    }
}

@@ -106,27 +106,20 @@
  String 
-application
+name
 ;%0A    pr
@@ -285,27 +285,20 @@
 (String 
-application
+name
 ) %7B%0A    
@@ -310,33 +310,19 @@
 his.
-application = application
+name = name
 ;%0A  
@@ -1509,35 +1509,28 @@
 beNames.get(
-application
+name
 );%0A    %7D%0A%0A  
@@ -1582,28 +1582,79 @@
 rts.get(
-application)
+name);%0A    %7D%0A%0A    public String getName() %7B%0A        return name
 ;%0A    %7D%0A
@@ -1887,37 +1887,23 @@
 als(
-application, that.application
+name, that.name
 );%0A 
@@ -1978,27 +1978,20 @@
 ts.hash(
-application
+name
 );%0A    %7D
@@ -2056,19 +2056,12 @@
 urn 
-application
+name
 ;%0A  

Allow us to get the name of an application