package com.libreecm.commonAPI.model.objects;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import com.libreecm.commonAPI.model.enums.BaseTypeId;
import com.libreecm.commonAPI.model.enums.Cardinality;
import com.libreecm.commonAPI.model.enums.MimeType;
import com.libreecm.commonAPI.model.enums.PropertyType;
import com.libreecm.commonAPI.model.enums.Updatability;
import com.libreecm.commonAPI.model.objects.properties.PropertyBooleanDefinitionImpl;
import com.libreecm.commonAPI.model.objects.properties.PropertyIdDefinitionImpl;
import com.libreecm.commonAPI.model.objects.properties.PropertyIntegerDefinitionImpl;
import com.libreecm.commonAPI.model.objects.properties.PropertyStringDefinitionImpl;

public class DocumentObjectType extends ObjectType {

	private Boolean versionable;
	private ContentStreamAllowed contentStreamAllowed;
	private String checkInComment;

	/**
	 * @return the isVersionable
	 */
	public Boolean isVersionable() {
		return versionable;
	}

	/**
	 * @param isVersionable the isVersionable to set
	 */
	public void setVersionable(Boolean isVersionable) {
		if (isVersionable==null) return;
		addBooleanProperty("cmis:versionable", isVersionable);
		this.versionable = isVersionable;
	}

	public DocumentObjectType() {
		super();

		List<String> contents=new ArrayList<>();
		for (ContentStreamAllowed content: ContentStreamAllowed.values()){
			contents.add(content.value());
		}
		Choice<String> choice = new Choice<String>();
		choice.setDisplayName("Content Stream Allowed Types");
		choice.setValue(contents);
		List<Choice<String>> choices = new ArrayList<>();
		choices.add(choice);
		
		
		List<Boolean> defaultBooleanTrue=new ArrayList<>();
		defaultBooleanTrue.add(true);
		
		List<Choice<Boolean>> boolChoices = new ArrayList<>();
		Choice<Boolean> boolChoice = new Choice<Boolean>();
		boolChoice.setDisplayName("Boolean");

		List<Boolean> defaultBooleans=new ArrayList<>();
		defaultBooleans.add(true);
		defaultBooleans.add(false);
		
		boolChoice.setValue(defaultBooleans);
		boolChoices.add(boolChoice);
		

		List<Choice<String>> mimeTypesChoices= new ArrayList<>();
		Choice<String> mimeChoice = new Choice<String>();
		mimeChoice.setDisplayName("Mime-Types");
		mimeChoice.setValue(new ArrayList<String>(MimeType.getMimeTypes()));
		mimeTypesChoices.add(mimeChoice);
		
		this.getPropertyDefinitions().put("cmis:isImmutable",new PropertyBooleanDefinitionImpl					("isImmutable", "cmis:isImmutable","isImmutable","","cmis:isImmutable","cmis:isImmutable", PropertyType.BOOLEAN,Cardinality.SINGLE,Updatability.READONLY,false,false,false,false,new ArrayList<Boolean>(),false,boolChoices));
		this.getPropertyDefinitions().put("cmis:isLatestVersion",new PropertyBooleanDefinitionImpl				("isLatestVersion","cmis:isLatestVersion","isLatestVersion","","cmis:isLatestVersion","cmis:isLatestVersion",PropertyType.BOOLEAN,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,true,false,false,false,new ArrayList<Boolean>(),false,boolChoices));
		this.getPropertyDefinitions().put("cmis:isMajorVersion",new PropertyBooleanDefinitionImpl			("isMajorVersion","cmis:isMajorVersion","isMajorVersion","","cmis:isMajorVersion","cmis:isMajorVersion",PropertyType.BOOLEAN,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,false,false,false,false,new ArrayList<Boolean>(),false,boolChoices));
		this.getPropertyDefinitions().put("cmis:isLatestMajorVersion",new PropertyBooleanDefinitionImpl		("isLatestMajorVersion","cmis:isLatestMajorVersion","isLatestMajorVersion","","cmis:isLatestMajorVersion","cmis:isLatestMajorVersion",PropertyType.BOOLEAN,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,true,true,false,false,new ArrayList<Boolean>(),false,boolChoices));
		this.getPropertyDefinitions().put("cmis:versionLabel",new PropertyStringDefinitionImpl			("versionLabel","cmis:versionLabel","versionLabel","","cmis:versionLabel","cmis:versionLabel",PropertyType.STRING,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,true,true,false,false,new ArrayList<String>(),false,new ArrayList<Choice<String>>()));
		this.getPropertyDefinitions().put("cmis:versionSeriesId",new PropertyIdDefinitionImpl			("versionSeriesId","cmis:versionSeriesId","versionSeriesId","","cmis:versionSeriesId","cmis:versionSeriesId",PropertyType.ID,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,false,false,false,false,new ArrayList<String>(),false,new ArrayList<Choice<String>>()));
		this.getPropertyDefinitions().put("cmis:isVersionSeriesCheckedOut",new PropertyBooleanDefinitionImpl("isVersionSeriesCheckedOut","cmis:isVersionSeriesCheckedOut","isVersionSeriesCheckedOut","","cmis:isVersionSeriesCheckedOut","cmis:isVersionSeriesCheckedOut",PropertyType.BOOLEAN,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,true,true,false,false,new ArrayList<Boolean>(),false,boolChoices));
		this.getPropertyDefinitions().put("cmis:versionSeriesCheckedOutBy",new PropertyStringDefinitionImpl	("versionSeriesCheckedOutBy","cmis:versionSeriesCheckedOutBy","versionSeriesCheckedOutBy","","cmis:versionSeriesCheckedOutBy","cmis:ersionSeriesCheckedOutBy",PropertyType.STRING,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,true,true,false,false,new ArrayList<String>(),true,new ArrayList<Choice<String>>()));
		this.getPropertyDefinitions().put("cmis:versionSeriesCheckedOutId",new PropertyIdDefinitionImpl	("versionSeriesCheckedOutId","cmis:versionSeriesCheckedOutId","versionSeriesCheckedOutId","","cmis:versionSeriesCheckedOutId","cmis:versionSeriesCheckedOutId",PropertyType.ID,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,true,true,true,false,new ArrayList<String>(),true,new ArrayList<Choice<String>>()));
		this.getPropertyDefinitions().put("cmis:checkinComment",new PropertyStringDefinitionImpl				("checkIn Comment","cmis:checkinComment","checkIn Comment","","cmis:checkinComment","cmis:checkinComment",PropertyType.STRING,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,true,false,false,false,new ArrayList<String>(),true,new ArrayList<Choice<String>>()));
		this.getPropertyDefinitions().put("cmis:contentStreamLength",new PropertyIntegerDefinitionImpl			("contentStreamLength","cmis:contentStreamLength","contentStreamLength","","cmis:contentStreamLength","cmis:contentStreamLength",PropertyType.INTEGER,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,true,false,true,false,new ArrayList<BigInteger>(),true,new ArrayList<Choice<BigInteger>>()));
		this.getPropertyDefinitions().put("cmis:contentStreamFileName",new PropertyStringDefinitionImpl			("contentStreamFileName","cmis:contentStreamFileName","contentStreamFileName","","cmis:contentStreamFileName","cmis:contentStreamFileName",PropertyType.STRING,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,false,false,false,false,new ArrayList<String>(),true,new ArrayList<Choice<String>>()));
		this.getPropertyDefinitions().put("cmis:contentStreamId",new PropertyIdDefinitionImpl			("contentStreamId","cmis:contentStreamId","contentStreamId","","cmis:contentStreamId","cmis:contentStreamId",PropertyType.ID,Cardinality.SINGLE,Updatability.ONCREATE,false,false,false,false,new ArrayList<String>(),true,new ArrayList<Choice<String>>()));
		this.getPropertyDefinitions().put("cmis:contentStreamMimeType",new PropertyStringDefinitionImpl			("contentStreamMimeType","cmis:contentStreamMimeType","contentStreamMimeType","","cmis:contentStreamMimeType","cmis:contentStreamMimeType",PropertyType.STRING,Cardinality.SINGLE,Updatability.WHENCHECKEDOUT,true,false,false,false,new ArrayList<>(),false,mimeTypesChoices));
		this.getPropertyDefinitions().put("cmis:creatable",new PropertyBooleanDefinitionImpl			("creatable","cmis:creatable","creatable","","cmis:creatable","cmis:creatable",PropertyType.BOOLEAN,Cardinality.SINGLE,Updatability.ONCREATE,true,false,false,false,new ArrayList<>(),false,boolChoices));
		this.getPropertyDefinitions().put("cmis:versionable",new PropertyBooleanDefinitionImpl			("versionable","cmis:versionable","versionable","","cmis:versionable","cmis:versionable",PropertyType.BOOLEAN,Cardinality.SINGLE,Updatability.ONCREATE,true,false,false,false,new ArrayList<>(),false,boolChoices));
		this.getPropertyDefinitions().put("cmis:parentId",new PropertyStringDefinitionImpl			("Parent Id","cmis:parentId","Parent Id","","cmis:parentId","cmis:parentId",			PropertyType.STRING,Cardinality.SINGLE,Updatability.ONCREATE,													true,true,true,false,						new ArrayList<String>(),true,new ArrayList<Choice<String>>()));
		this.getPropertyDefinitions().put("cmis:contentStreamAllowed",new PropertyStringDefinitionImpl					("Content stream allowed","cmis:contentStreamAllowed","Content Stream allowed","","cmis:contentStreamAllowed","cmis:contentStreamAllowed",								PropertyType.STRING,Cardinality.SINGLE,Updatability.READONLY,			true,false,false,false,						new ArrayList<String>(),false,choices));
		this.getPropertyDefinitions().put("cmis:versionable",new PropertyBooleanDefinitionImpl				("Versionable","cmis:versionable","versionable","","cmis:versionable","cmis:versionable",									PropertyType.BOOLEAN,Cardinality.SINGLE,Updatability.READONLY,			false,true,true,false,						defaultBooleanTrue,false,boolChoices));

		this.setId(BaseTypeId.CMIS_DOCUMENT.value());
		this.setBaseTypeId(BaseTypeId.CMIS_DOCUMENT);
		this.setParentTypeId(BaseTypeId.CMIS_DOCUMENT.value());
	}

	public ContentStreamAllowed getContentStreamAllowed() {
		return this.contentStreamAllowed;
	}

	/**
	 * @param contentStreamAllowed the contentStreamAllowed to set
	 */
	public void setContentStreamAllowed(ContentStreamAllowed contentStreamAllowed) {
		if (contentStreamAllowed==null) return;
		addStringProperty("cmis:contentStreamAllowed", contentStreamAllowed.value());
		this.contentStreamAllowed = contentStreamAllowed;
	}

}
