package com.libreecm.db.jpa;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.persistence.*;

import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
public class CreatablePropertyTypesImpl  extends LibreECMObject implements org.apache.chemistry.opencmis.commons.data.CreatablePropertyTypes{

	@Id
	@GeneratedValue(generator="hilo-gen")
	@GenericGenerator(name="hilo-gen", strategy="hilo")
	private Integer id;

	public String getId() {
		if (id==null){
			return null;
		}
		return id.toString();
	}
    
	private static final long serialVersionUID = 1L;


	public CreatablePropertyTypesImpl(){
		this.id=0;
	}
	
    public CreatablePropertyTypesImpl(Set<PropertyType> propertyTypeSet,
			List<CmisExtensionElementImpl> cmisExtensionElements) {
		super();
		this.propertyTypeSet = propertyTypeSet;
		this.cmisExtensionElements = cmisExtensionElements;
		this.id=0;
    }

	/**
    * A collection of properties types changed by this 
    */
    @ElementCollection(targetClass=PropertyType.class)
    private Set<PropertyType> propertyTypeSet;
	
    @OneToMany
    private List<CmisExtensionElementImpl> cmisExtensionElements;
	
	/**
	 * @return the propertyTypeSet
	 */
	public Set<PropertyType> getPropertyTypeSet() {
		return propertyTypeSet;
	}

	/**
	 * @param propertyTypeSet the propertyTypeSet to set
	 */
	public void setPropertyTypeSet(Set<PropertyType> propertyTypeSet) {
		this.propertyTypeSet = propertyTypeSet;
	}

	/**
	 * @return the cmisExtensionElements
	 */
	public List<CmisExtensionElementImpl> getCmisExtensionElements() {
		return cmisExtensionElements;
	}

	/**
	 * @param cmisExtensionElements the cmisExtensionElements to set
	 */
	public void setCmisExtensionElements(List<CmisExtensionElementImpl> cmisExtensionElements) {
		this.cmisExtensionElements = cmisExtensionElements;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		if (id==null){
			this.id=null;
		}
		this.id = Integer.parseInt(id);
	}

	@JsonIgnore
	@Deprecated
	public Set<PropertyType> canCreate() {
	     if (propertyTypeSet == null) {
	         propertyTypeSet = new HashSet<PropertyType>();
	     }
	    return propertyTypeSet;
	}
	
	@JsonIgnore
	@Deprecated
	public void setCanCreate(Set<PropertyType> propertyTypeSet) {
	      this.propertyTypeSet = propertyTypeSet;
	}

	@JsonIgnore
	@Deprecated
	public List<CmisExtensionElement> getExtensions() {
		ArrayList<CmisExtensionElement> array= new ArrayList<CmisExtensionElement>();
		array.addAll(this.cmisExtensionElements);
		return array;
	} 

	@JsonIgnore
	@Deprecated
	public void setExtensions(List<CmisExtensionElement> arg0) {
	this.cmisExtensionElements=new ArrayList<CmisExtensionElementImpl>();
	Iterator<CmisExtensionElement> it = arg0.iterator();
		while (it.hasNext()){
			this.cmisExtensionElements.add((CmisExtensionElementImpl) it.next());
		}		
	}
 
}
