package com.celements.web.classes.oldcore;

import java.util.List;

import javax.inject.Singleton;

import org.xwiki.component.annotation.Component;

import com.celements.model.classes.AbstractClassDefinition;
import com.celements.model.classes.fields.BooleanField;
import com.celements.model.classes.fields.ClassField;
import com.celements.model.classes.fields.list.AccessRightLevelsField;
import com.celements.model.classes.fields.list.ListOfGroupsField;
import com.celements.model.classes.fields.list.ListOfUsersField;
import com.celements.rights.access.EAccessLevel;
import com.xpn.xwiki.user.api.XWikiUser;

@Singleton
@Component(XWikiRightsClass.CLASS_DEF_HINT)
public class XWikiRightsClass extends AbstractClassDefinition implements IOldCoreClassDef {

  public static final String CLASS_SPACE = "XWiki";
  public static final String CLASS_NAME = "XWikiRights";
  public static final String CLASS_FN = CLASS_SPACE + "." + CLASS_NAME;
  public static final String CLASS_DEF_HINT = CLASS_FN;

  public static final String FIELD_ALLOW_NAME = "allow";
  public static final String FIELD_ALLOW_PRETTY_NAME = "Allow/Deny";
  public static final String FIELD_ACCESSLVL_NAME = "levels";
  public static final String FIELD_ACCESSLVL_PRETTY_NAME = "Levels";
  public static final String FIELD_USERS_NAME = "users";
  public static final String FIELD_USERS_PRETTY_NAME = "Users";
  public static final String FIELD_GROUPS_NAME = "groups";
  public static final String FIELD_GROUPS_PRETTY_NAME = "Groups";

  public static final ClassField<Boolean> FIELD_ALLOW = new BooleanField.Builder(CLASS_FN,
      FIELD_ALLOW_NAME).prettyName(FIELD_ALLOW_PRETTY_NAME).displayFormType("select").displayType(
          FIELD_ALLOW_NAME).defaultValue(1).build();
  public static final ClassField<List<String>> FIELD_GROUPS = new ListOfGroupsField.Builder(
      CLASS_FN, FIELD_GROUPS_NAME).prettyName(FIELD_GROUPS_PRETTY_NAME).displayType(
          "select").multiSelect(true).size(5).usesList(true).build();
  public static final ClassField<List<EAccessLevel>> FIELD_LEVELS = new AccessRightLevelsField.Builder(
      CLASS_FN, FIELD_ACCESSLVL_NAME).prettyName(FIELD_ACCESSLVL_PRETTY_NAME).displayType(
          "select").multiSelect(true).size(3).build();
  public static final ClassField<List<XWikiUser>> FIELD_USERS = new ListOfUsersField.Builder(
      CLASS_FN, FIELD_USERS_NAME).prettyName(FIELD_USERS_PRETTY_NAME).displayType(
          "select").multiSelect(true).size(5).usesList(true).build();

  @Override
  public String getName() {
    return CLASS_FN;
  }

  @Override
  public boolean isInternalMapping() {
    return false;
  }

  @Override
  protected String getClassSpaceName() {
    return CLASS_SPACE;
  }

  @Override
  protected String getClassDocName() {
    return CLASS_NAME;
  }

}

@@ -1027,26 +1027,26 @@
 g FIELD_
+NAME_
 ALLOW
-_NAME
  = %22allo
@@ -1080,30 +1080,24 @@
 tring FIELD_
-ALLOW_
 PRETTY_NAME 
@@ -1091,24 +1091,30 @@
 _PRETTY_NAME
+_ALLOW
  = %22Allow/De
@@ -1145,32 +1145,37 @@
 al String FIELD_
+NAME_
 ACCESSLVL_NAME =
@@ -1167,21 +1167,16 @@
 CCESSLVL
-_NAME
  = %22leve
@@ -1211,34 +1211,24 @@
 tring FIELD_
-ACCESSLVL_
 PRETTY_NAME 
@@ -1222,24 +1222,34 @@
 _PRETTY_NAME
+_ACCESSLVL
  = %22Levels%22;
@@ -1284,26 +1284,26 @@
 g FIELD_
+NAME_
 USERS
-_NAME
  = %22user
@@ -1337,30 +1337,24 @@
 tring FIELD_
-USERS_
 PRETTY_NAME 
@@ -1348,24 +1348,30 @@
 _PRETTY_NAME
+_USERS
  = %22Users%22;%0A
@@ -1405,27 +1405,27 @@
 g FIELD_
+NAME_
 GROUPS
-_NAME
  = %22grou
@@ -1460,31 +1460,24 @@
 tring FIELD_
-GROUPS_
 PRETTY_NAME 
@@ -1471,24 +1471,31 @@
 _PRETTY_NAME
+_GROUPS
  = %22Groups%22;
@@ -1599,26 +1599,26 @@
   FIELD_
+NAME_
 ALLOW
-_NAME
 ).pretty
@@ -1628,22 +1628,16 @@
 e(FIELD_
-ALLOW_
 PRETTY_N
@@ -1631,32 +1631,38 @@
 IELD_PRETTY_NAME
+_ALLOW
 ).displayFormTyp
@@ -1706,18 +1706,18 @@
 ELD_
+NAME_
 ALLOW
-_NAME
 ).de
@@ -1858,19 +1858,19 @@
 ELD_
+NAME_
 GROUPS
-_NAME
 ).pr
@@ -1888,15 +1888,8 @@
 ELD_
-GROUPS_
 PRET
@@ -1887,32 +1887,39 @@
 IELD_PRETTY_NAME
+_GROUPS
 ).displayType(%0A 
@@ -2109,24 +2109,29 @@
 S_FN, FIELD_
+NAME_
 ACCESSLVL_NA
@@ -2127,21 +2127,16 @@
 CCESSLVL
-_NAME
 ).pretty
@@ -2150,18 +2150,8 @@
 ELD_
-ACCESSLVL_
 PRET
@@ -2149,32 +2149,42 @@
 IELD_PRETTY_NAME
+_ACCESSLVL
 ).displayType(%0A 
@@ -2357,18 +2357,18 @@
 ELD_
+NAME_
 USERS
-_NAME
 ).pr
@@ -2386,14 +2386,8 @@
 ELD_
-USERS_
 PRET
@@ -2393,16 +2393,22 @@
 TTY_NAME
+_USERS
 ).displa

rename constants to make distinction between name / pretty name clearer