package de.ivu.elect.presentation.email.form;

import de.ivu.elect.business.email.entity.EmailLayout;
import de.ivu.elect.business.email.entity.EmailLayoutProperties;
import de.ivu.elect.jee.presentation.dynamicform.FormBuilder;
import de.ivu.elect.jee.presentation.dynamicform.PropertyType;
import de.ivu.elect.presentation.ViewFormBuilder;

import javax.inject.Inject;

public class EmailLayoutViewFormBuilder extends ViewFormBuilder {

  private static final long serialVersionUID = 1L;

  @Inject
  private EmailLayoutUniqueUKFacesValidator emailLayoutUniqueUKFacesValidator;

  @Inject
  private EmailLayoutPlatzhalterFacesValidator emailLayoutPlatzhalterFacesValidator;

  public EmailLayoutViewFormBuilder() {
    super();
  }

  public void addEmailLayoutProperties(FormBuilder formBuilder, EmailLayout emailLayout) {
    EmailLayoutProperties emailLayoutProperties = emailLayout.getProperties();

    formBuilder.addProperty(emailLayoutProperties.getBezeichnungProperty())
        .withValidatorAndPk(emailLayoutUniqueUKFacesValidator, emailLayout.getPk());
    formBuilder.addProperty(emailLayoutProperties.getVerwendungTypProperty());
    formBuilder.addProperty(emailLayoutProperties.getInhaltProperty()).withType(PropertyType.INPUT_TEXTAREA)
        .withValidator(emailLayoutPlatzhalterFacesValidator);
    formBuilder.addProperty(new EmailLayoutPlatzhalterErlaeuterungProperty());
  }
}
