package de.ivu.elect.presentation.mandant;

import de.ivu.elect.business.mandant.entity.Mandant;
import de.ivu.elect.business.security.control.ElectCommonPrincipal;

import javax.inject.Inject;
import java.io.Serializable;

public class MandantSessionSelect implements Serializable {
  private static final long serialVersionUID = 1L;

  @Inject
  private transient ElectCommonPrincipal principal;

  public Mandant getMandant() {
    return principal.getMandant();
  }

  public Long getMandantNummer() {
    Mandant mandant = getMandant();
    if (mandant == null) {
      return null;
    }
    return mandant.getNummer();
  }


  @Deprecated
  public Mandant getMandantOrNull() {
    try {
      return getMandant();
    } catch (Exception e) {
      // kein Principal? Hintergrundprozess?
    }
    return null;
  }
}
