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

import static de.ivu.elect.business.security.Customer.BASE;
import static de.ivu.elect.business.security.Customer.CORE;
import static de.ivu.elect.business.security.Customer.WVZ;
import static java.util.Arrays.asList;

import java.util.ArrayList;
import java.util.Collection;

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

public enum StaatenGruppeTyp {

  UNBEKANNT(BASE),

  MINDERHEIT_AUSLAENDERBEIRATSWAHL(CORE),

  WAHLRECHTSKRITERIUM_STAATSANGEHOERIGKEIT(WVZ),

  STAATEN_DER_EU(WVZ);

  private final Collection<Customer> supportedCustomers;

  private StaatenGruppeTyp(Customer... supportedCustomers) {
    this.supportedCustomers = asList(supportedCustomers);
  }

  public boolean isSupported(CurrentCustomer currentCustomer) {
    if (currentCustomer != null && currentCustomer.getCustomer() != null) {
      return containsAny(currentCustomer.getCustomer().getContainedCustomers(), this.supportedCustomers);
    }

    return false;
  }

  private static boolean containsAny(Collection<Customer> actual, Collection<Customer> expected) {
    return new ArrayList<>(actual).removeAll(expected);
  }
}
