package de.ivu.elect.presentation.mandant.table;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import de.ivu.elect.business.mandant.entity.Mandant;
import de.ivu.elect.jee.presentation.dynamictable.AbstractColumnBuilder;
import de.ivu.elect.jee.presentation.dynamictable.ColumnEntry;
import de.ivu.elect.jee.presentation.dynamictable.ColumnType;
import de.ivu.elect.presentation.system.BasisUrlResolver;

@Named(MandantColumnBuilder.COMPONENT_NAME)
public class MandantColumnBuilder extends AbstractColumnBuilder<Mandant> {

  public static final String COMPONENT_NAME = "mandantColumnBuilder";

  private static final long serialVersionUID = 1L;

  private AbstractMandantColumn<Mandant> mandantNummerColumn;

  private AbstractMandantColumn<Mandant> mandantNameColumn;

  private AbstractMandantColumn<Mandant> mandantArtColumn;

  private AbstractMandantColumn<Mandant> mandantStatusColumn;

  private AbstractMandantColumn<Mandant> mandantBeschreibungColumn;

  private AbstractMandantColumn<Mandant> mandantSystemGebietsebeneColumn;

  private AbstractMandantColumn<Mandant> loginColumn;

  private AbstractMandantColumn<Mandant> mandantVerantworteteGebieteColumn;

  @Inject
  private transient BasisUrlResolver basisUrlResolver;

  public MandantColumnBuilder() {
    super();
  }

  @Override
  protected void initColumns() {

    mandantNummerColumn = AbstractMandantColumn.createMandantNummerColumn(getMessages());
    mandantNameColumn = AbstractMandantColumn.createMandantNameColumn(getMessages());
    mandantArtColumn = AbstractMandantColumn.createMandantArtColumn(getMessages());
    mandantStatusColumn = AbstractMandantColumn.createMandantStatusColumn(getMessages());
    mandantSystemGebietsebeneColumn = AbstractMandantColumn.createMandantSystemGebietsebeneColumn(getMessages());
    mandantVerantworteteGebieteColumn = AbstractMandantColumn.createMandantVerantworteteGebieteColumn(getMessages());
    mandantBeschreibungColumn = AbstractMandantColumn.createMandantBeschreibungColumn(getMessages());

    loginColumn = new AbstractMandantColumn<>("Login-Url", messages, "mandant.login.url", ColumnType.STRING, m -> m.getLoginUrl(basisUrlResolver));
  }

  @Override
  protected List<ColumnEntry<? super Mandant>> getColumnEntriesSorted() {
    List<ColumnEntry<? super Mandant>> result = new ArrayList<>();
    result.add(mandantNummerColumn);
    result.add(mandantNameColumn);
    result.add(mandantArtColumn);
    result.add(mandantStatusColumn);
    result.add(mandantSystemGebietsebeneColumn);
    result.add(mandantVerantworteteGebieteColumn);
    result.add(loginColumn);
    result.add(mandantBeschreibungColumn);
    return result;
  }
}
