
package de.ivu.elect.business.lokalisierung.entity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import de.ivu.elect.business.security.Customer;

public enum LokalisierungModul {

  ENTITIES(Customer.MINIMAL, "EntityMessages"),

  MINIMAL(Customer.MINIMAL, "messages_elect"),
  BASE(Customer.BASE, "messages_elect"),
  COMMON(Customer.COMMON, "messages_elect_common"),
  CORE(Customer.CORE, "messages_elect_core"),
  WES_CORE(Customer.WES, "messages_elect_core"),
  WAS(Customer.WAS, "messages_elect_was"),
  WES(Customer.WES, "messages_elect_wes"),
  WUS(Customer.WUS, "messages_elect_wus"),
  WOS(Customer.WOS, "messages_elect_wos"),
  WVZ(Customer.WVZ, "messages_elect_wvz"),

  BASE_CUSTOM(Customer.BASE, "messages_elect_custom"),
  COMMON_CUSTOM(Customer.COMMON, "messages_elect_common_custom"),
  CORE_CUSTOM(Customer.CORE, "messages_elect_core_custom"),
  CORE_WES_CUSTOM(Customer.WES, "messages_elect_core_custom"),
  WAS_CUSTOM(Customer.WAS, "messages_elect_was_custom"),
  WES_CUSTOM(Customer.WES, "messages_elect_wes_custom"),
  WUS_CUSTOM(Customer.WUS, "messages_elect_wus_custom"),
  WOS_CUSTOM(Customer.WOS, "messages_elect_wos_custom"),
  WVZ_CUSTOM(Customer.WVZ, "messages_elect_wvz_custom"),

  COMMON_CUSTOM_KOM(Customer.KOM_WAS, "messages_elect_common_custom_kom"),
  WAS_CUSTOM_KOM(Customer.KOM_WAS, "messages_elect_was_custom_kom"),
  WES_CUSTOM_KOM(Customer.KOM_WES, "messages_elect_wes_custom_kom"),
  WOS_CUSTOM_KOM(Customer.KOM_WOS, "messages_elect_wos_custom_kom"),

  ;

  private final String resourceFile;

  private final Customer customer;

  LokalisierungModul(Customer customer, String resourceFile) {
    this.customer = customer;
    this.resourceFile = resourceFile;
  }

  public String getResourceFile() {
    return resourceFile;
  }

  public Customer getCustomer() {
    return customer;
  }

  public static List<LokalisierungModul> getModuleForCustomer(Customer customer) {
    Set<LokalisierungModul> verwendeteModule = new HashSet<>();

    for (Customer contained : customer.getContainedCustomers()) {
      for (LokalisierungModul lokalisierungModul : values()) {
        if (lokalisierungModul.getCustomer().equals(contained)) {
          verwendeteModule.add(lokalisierungModul);
        }
      }
    }

    List<LokalisierungModul> sortiertNachDefinitionInEnum = new ArrayList<>(verwendeteModule);
    Collections.sort(sortiertNachDefinitionInEnum);

    return sortiertNachDefinitionInEnum;
  }
}
