package com.celements.model.classes.fields;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.validation.constraints.NotNull;

import com.google.common.base.Preconditions;
import com.xpn.xwiki.objects.classes.BooleanClass;
import com.xpn.xwiki.objects.classes.PropertyClass;

@Immutable
public final class BooleanField extends AbstractClassField<Boolean> implements
    CustomClassField<Boolean> {

  private final String displayType;
  private final Integer defaultValue;

  public static class Builder extends AbstractClassField.Builder<Builder, Boolean> {

    private String displayType;
    private Integer defaultValue;

    public Builder(@NotNull String classDefName, @NotNull String name) {
      super(classDefName, name);
    }

    @Override
    public Builder getThis() {
      return this;
    }

    public Builder displayType(@Nullable String val) {
      displayType = val;
      return getThis();
    }

    public Builder defaultValue(@Nullable Integer val) {
      defaultValue = val;
      return getThis();
    }

    @Override
    public BooleanField build() {
      return new BooleanField(getThis());
    }
  }

  protected BooleanField(@NotNull Builder builder) {
    super(builder);
    this.displayType = builder.displayType;
    this.defaultValue = builder.defaultValue;
  }

  @Override
  public Class<Boolean> getType() {
    return Boolean.class;
  }

  public String getDisplayType() {
    return displayType;
  }

  public Integer getDefaultValue() {
    return defaultValue;
  }

  @Override
  protected PropertyClass getPropertyClass() {
    BooleanClass element = new BooleanClass();
    if (displayType != null) {
      element.setDisplayType(displayType);
    }
    if (defaultValue != null) {
      element.setDefaultValue(defaultValue);
    }
    return element;
  }

  @Override
  public Object serialize(Boolean value) {
    if (value == null) {
      return null;
    }
    return value ? 1 : 0;
  }

  @Override
  public Boolean resolve(Object obj) {
    if (obj == null) {
      return null;
    }
    Preconditions.checkArgument(obj.getClass().equals(Integer.class));
    return !((Integer) obj).equals(0);
  }

}

@@ -436,16 +436,56 @@
 ean%3E %7B%0A%0A
+  private final String displayFormType;%0A
   privat
@@ -508,24 +508,24 @@
 isplayType;%0A
-
   private fi
@@ -637,16 +637,52 @@
 ean%3E %7B%0A%0A
+    private String displayFormType;%0A
     priv
@@ -916,32 +916,151 @@
 rn this;%0A    %7D%0A%0A
+    public Builder displayFormType(@Nullable String val) %7B%0A      displayFormType = val;%0A      return getThis();%0A    %7D%0A%0A
     public Build
@@ -1442,16 +1442,68 @@
 ilder);%0A
+    this.displayFormType = builder.displayFormType;%0A
     this
@@ -1664,24 +1664,96 @@
 class;%0A  %7D%0A%0A
+  public String getDisplayFormType() %7B%0A    return displayFormType;%0A  %7D%0A%0A
   public Str
@@ -1926,24 +1926,24 @@
 tyClass() %7B%0A
-
     BooleanC
@@ -1973,24 +1973,116 @@
 eanClass();%0A
+    if (displayFormType != null) %7B%0A      element.setDisplayFormType(displayFormType);%0A    %7D%0A
     if (disp

add displayFormType to BooleanField