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.data.CreatablePropertyTypes;
import org.apache.chemistry.opencmis.commons.data.NewTypeSettableAttributes;
import org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities;
import org.apache.chemistry.opencmis.commons.enums.*;
import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="repository_capabilities")
public class RepositoryCapabilitiesImpl  extends LibreECMObject implements RepositoryCapabilities {//implements org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities{


	@Transient
    private static final long serialVersionUID = 2L;
    
    @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 Boolean allVersionsSearchableSupported;
    private Boolean isPwcSearchable;
    private Boolean isPwcUpdatable;
    private Boolean supportsGetDescendants;
    private Boolean supportsGetFolderTree;
    @Enumerated(EnumType.STRING)
    private CapabilityOrderBy orderByCapability;
    private Boolean supportsMultifiling;
    private Boolean supportsUnfiling;
    private Boolean supportsVersionSpecificFiling;
    private NewTypeSettableAttributesImpl newTypeSettableAttributes;
    @Enumerated(EnumType.STRING)
	private CapabilityRenditions capabilityRenditions;
	@Enumerated(EnumType.STRING)
	private CapabilityAcl aclCapability;
	@Enumerated(EnumType.STRING)
	private CapabilityJoin joinCapability;
	@Enumerated(EnumType.STRING)
	private CapabilityChanges changesCapability;
	@Enumerated(EnumType.STRING)
	private CapabilityContentStreamUpdates contentStreamUpdatesCapability;
	@Enumerated(EnumType.STRING)
	private CapabilityQuery queryCapability;
	private CreatablePropertyTypesImpl creatablePropertyTypes;

	//@JoinColumn(name="property_type_set_id", referencedColumnName="id")
    /**
    * A collection of additional properties supported by this repository
    */
	@ElementCollection(targetClass=PropertyType.class)
    private Set<PropertyType> propertyTypeSet=new HashSet<PropertyType>();
	 
	@OneToMany
	//@JsonSerialize(as=List.class)
	/**
	* A collection of additional Cmis extensions elements supported by this repository
	*/
    private List<CmisExtensionElementImpl> cmisExtensionElements;

    /**
     * Constructor.
     */
    public RepositoryCapabilitiesImpl() {
    }

	public RepositoryCapabilitiesImpl(Boolean allVersionsSearchable, Boolean isPwcSearchable, Boolean isPwcUpdatable,
			Boolean supportsGetDescendants, Boolean supportsGetFolderTree, CapabilityOrderBy capabilityOrderBy,
			Boolean supportsMultifiling, Boolean supportsUnfiling, Boolean supportsVersionSpecificFiling,
			NewTypeSettableAttributesImpl newTypeSettableAttributes, CapabilityRenditions capabilityRenditions,
			CapabilityAcl aclCapability, CapabilityJoin capabilityJoin, CapabilityChanges capabilityChanges,
			CapabilityContentStreamUpdates capabilityContentStreamUpdates, CapabilityQuery capabilityQuery,
			CreatablePropertyTypesImpl creatablePropertyTypes, Set<PropertyType> propertyTypeSet,
			List<CmisExtensionElementImpl> cmisExtensionElement) {
		super();
		this.allVersionsSearchableSupported = allVersionsSearchable;
		this.isPwcSearchable = isPwcSearchable;
		this.isPwcUpdatable = isPwcUpdatable;
		this.supportsGetDescendants = supportsGetDescendants;
		this.supportsGetFolderTree = supportsGetFolderTree;
		this.orderByCapability = capabilityOrderBy;
		this.supportsMultifiling = supportsMultifiling;
		this.supportsUnfiling = supportsUnfiling;
		this.supportsVersionSpecificFiling = supportsVersionSpecificFiling;
		this.newTypeSettableAttributes = newTypeSettableAttributes;
		this.capabilityRenditions = capabilityRenditions;
		this.aclCapability = aclCapability;
		this.joinCapability = capabilityJoin;
		this.changesCapability = capabilityChanges;
		this.contentStreamUpdatesCapability = capabilityContentStreamUpdates;
		this.queryCapability = capabilityQuery;
		this.creatablePropertyTypes = creatablePropertyTypes;
		this.propertyTypeSet = propertyTypeSet;
		this.cmisExtensionElements = cmisExtensionElement;
	}


    @JsonIgnore
    @Deprecated
	public Boolean isAllVersionsSearchableSupported() {
        return allVersionsSearchableSupported;
    }

    public void setAllVersionsSearchableSupported(Boolean allVersionsSearchableSupported) {
        this.allVersionsSearchableSupported = allVersionsSearchableSupported;
    }
    
    public void setAclCapability(CapabilityAcl aclCapability) {
        this.aclCapability = aclCapability;
    }

    public void setChangesCapability(CapabilityChanges capabilityChanges) {
        this.changesCapability = capabilityChanges;
    }

    public void setContentStreamUpdatesCapability(CapabilityContentStreamUpdates capabilityContentStreamUpdates) {
        this.contentStreamUpdatesCapability = capabilityContentStreamUpdates;
    }

    public void setJoinCapability(CapabilityJoin capabilityJoin) {
        this.joinCapability = capabilityJoin;
    }
    
    public CapabilityQuery getQueryCapability() {
        return queryCapability;
    }

    public void setQueryCapability(CapabilityQuery capabilityQuery) {
        this.queryCapability = capabilityQuery;
    }

    @JsonIgnore
    @Deprecated
    public Boolean isPwcSearchableSupported() {
        return isPwcSearchable;
    }

    public void setIsPwcSearchable(Boolean isPwcSearchable) {
        this.isPwcSearchable = isPwcSearchable;
    }

    @JsonIgnore
    @Deprecated
    public Boolean isPwcUpdatableSupported() {
        return isPwcUpdatable;
    }

    @JsonIgnore
    @Deprecated
    public void setIsPwcUpdatable(Boolean isPwcUpdatable) {
        this.isPwcUpdatable = isPwcUpdatable;
    }

    @JsonIgnore
    @Deprecated
    public Boolean isGetDescendantsSupported() {
        return supportsGetDescendants;
    }

    public void setSupportsGetDescendants(Boolean supportsGetDescendants) {
        this.supportsGetDescendants = supportsGetDescendants;
    }


    @JsonIgnore
    @Deprecated
    public Boolean isGetFolderTreeSupported() {
        return supportsGetFolderTree;
    }

    public void setSupportsGetFolderTree(Boolean supportsGetFolderTree) {
        this.supportsGetFolderTree = supportsGetFolderTree;
    }

    public void setOrderByCapability(CapabilityOrderBy capabilityOrderBy) {
        this.orderByCapability = capabilityOrderBy;
    }

    @JsonIgnore
    @Deprecated
    public Boolean isMultifilingSupported() {
        return supportsMultifiling;
    }

    public void setSupportsMultifiling(Boolean supportsMultifiling) {
        this.supportsMultifiling = supportsMultifiling;
    }

    public Set<PropertyType> getPropertyTypeSet() {
    	return propertyTypeSet;
    }


	public void setPropertyTypeSet(Set<PropertyType> propertyTypeSet) {
		this.propertyTypeSet = propertyTypeSet;
	}

	public void setRenditionsCapability(CapabilityRenditions capabilityRenditions) {
		this.capabilityRenditions = capabilityRenditions;
	}

	public Boolean getAllVersionsSearchableSupported() {
		return allVersionsSearchableSupported;
	}


	public Boolean getIsPwcSearchable() {
		return isPwcSearchable;
	}


	public Boolean getIsPwcUpdatable() {
		return isPwcUpdatable;
	}


	public Boolean getSupportsGetDescendants() {
		return supportsGetDescendants;
	}


	public Boolean getSupportsGetFolderTree() {
		return supportsGetFolderTree;
	}

	public Boolean getSupportsMultifiling() {
		return supportsMultifiling;
	}


	public Boolean getSupportsUnfiling() {
		return supportsUnfiling;
	}


	public Boolean getSupportsVersionSpecificFiling() {
		return supportsVersionSpecificFiling;
	}

	public void setId(String id) {
		this.id = Integer.parseInt(id);
	}

	@Deprecated
	@JsonIgnore
	public Boolean isUnfilingSupported() {
        return supportsUnfiling;
    }

    public void setSupportsUnfiling(Boolean supportsUnfiling) {
        this.supportsUnfiling = supportsUnfiling;
    }

    @Deprecated
    @JsonIgnore
    public Boolean isVersionSpecificFilingSupported() {
        return supportsVersionSpecificFiling;
    }

    public void setSupportsVersionSpecificFiling(Boolean supportsVersionSpecificFiling) {
        this.supportsVersionSpecificFiling = supportsVersionSpecificFiling;
    }

    public CreatablePropertyTypes getCreatablePropertyTypes() {
        return creatablePropertyTypes;
    }

    public void setCreatablePropertyTypes(CreatablePropertyTypesImpl creatablePropertyTypes) {
        this.creatablePropertyTypes = creatablePropertyTypes;
    }

    public NewTypeSettableAttributes getNewTypeSettableAttributes() {
        if (this.newTypeSettableAttributes==null){
        	this.newTypeSettableAttributes=new NewTypeSettableAttributesImpl();
        }
    	return newTypeSettableAttributes;
    }

    public void setNewTypeSettableAttributes(NewTypeSettableAttributesImpl newTypeSettableAttributes) {
        this.newTypeSettableAttributes =  newTypeSettableAttributes;
    }

    //@Override
	public List<CmisExtensionElementImpl> getCmisExtensionElements() {
		if (this.cmisExtensionElements==null){
			this.cmisExtensionElements=new ArrayList<>();
		}
		return this.cmisExtensionElements;
	} 

    public void setCmisExtensionElements(List<CmisExtensionElementImpl> arg0) {
    	this.cmisExtensionElements=arg0;
	}
	
    //@Override
	@JsonIgnore
	@Deprecated
	public List<CmisExtensionElement> getExtensions() {
		//return this.cmisExtensionElement;
		ArrayList<CmisExtensionElement> array= new ArrayList<CmisExtensionElement>();
		array.addAll(getCmisExtensionElements());
		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());
		}
		//this.cmisExtensionElement=arg0;
	}
    
	public CapabilityContentStreamUpdates getContentStreamUpdatesCapability() {
		return this.contentStreamUpdatesCapability;
	}

	public CapabilityChanges getChangesCapability() {
		return changesCapability;
	}

	public CapabilityOrderBy getOrderByCapability() {
		return orderByCapability;
	}

	public CapabilityJoin getJoinCapability() {
		return joinCapability;
	}
	
	public CapabilityAcl getAclCapability() {
		return aclCapability;
	}

	@Override
	public CapabilityRenditions getRenditionsCapability() {
		return this.capabilityRenditions;
	}

}
