
package de.ivu.elect.business.system.control;

import java.util.Collection;

import javax.inject.Inject;

import de.ivu.elect.business.konfiguration.control.AbstractKonfigurationInit;
import de.ivu.elect.business.konfiguration.entity.ElectKonfigurationWerte;
import de.ivu.elect.business.konfiguration.entity.Konfiguration;
import de.ivu.elect.business.konfiguration.entity.KonfigurationInitContext;
import de.ivu.elect.business.konfiguration.entity.MandantKonfigurationWerte;
import de.ivu.elect.business.system.entity.HttpSessionTracking;


import static java.util.Arrays.asList;

public class HttpSessionKonfigurationInit extends AbstractKonfigurationInit {

  public static final int DEFAULT_SESSION_TIMEOUT_IN_MINUTES = 30;

  @Inject
  private transient HttpSessionKonfigurationSecure httpSessionKonfigurationSecure;

  public HttpSessionKonfigurationInit() {
    super();
  }

  @Override
  protected Collection<Konfiguration> createDefaultParameters(KonfigurationInitContext konfigurationInitContext) {
    return asList( //
        create(MandantKonfigurationWerte.HTTP_SESSION_TIMEOUT_IN_MINUTEN, getDefaultSessionTimeoutInMinutes()), //
        create(ElectKonfigurationWerte.HTTP_SESSION_TRACKING_MODE, getDefaultSessionTrackingMode().name()), //
        create(ElectKonfigurationWerte.HTTP_LOGGING_LOGIN_ACCESS, getDefaultLoggingLoginAccess()), //
        create(ElectKonfigurationWerte.HTTP_FORCE_HOSTNAME, getDefaultHttpForceHostname()), //
        create(ElectKonfigurationWerte.HTTP_SESSION_COOKIE_CONFIG_HTTP_ONLY, getDefaultCookieConfigHttpOnly()), //
        create(ElectKonfigurationWerte.HTTP_SESSION_COOKIE_CONFIG_SECURE, getDefaultCookieSecureOnly()) //
    );
  }

  protected String getDefaultHttpForceHostname() {
    return "";
  }

  protected Boolean getDefaultLoggingLoginAccess() {
    return Boolean.FALSE;
  }

  protected int getDefaultSessionTimeoutInMinutes() {
    return DEFAULT_SESSION_TIMEOUT_IN_MINUTES;
  }

  protected HttpSessionTracking getDefaultSessionTrackingMode() {
    return HttpSessionTracking.DEFAULT;
  }

  protected Boolean getDefaultCookieConfigHttpOnly() {
    return Boolean.TRUE; // ELECTVAPP-373  WASDE-1547 ELECTKOM-1262
  }

  protected Boolean getDefaultCookieSecureOnly() {
    return httpSessionKonfigurationSecure.isSecureSystemOnly();
  }
}
