package com.github.dkharrat.nexusdata.core;

import java.util.HashMap;
import java.util.Map;

/**
 * Represents the data cache for a single record in the persistent store. It's used by the framework to retrieve and
 * store the data of the corresponding managed object from and to the persistent store.
 *
 * Internally, a StoreCacheNode is simply a key/value store to get or set value of individual properties.
 * A value can contain references to other ObjectIDs if the property is a relationship.
 */
public class StoreCacheNode {
    private final ObjectID id;
    private Map<String,Object> properties = new HashMap<String,Object>();

    /**
     * Creates a new StoreCacheNode that's associated with the specified ObjectID
     *
     * @param id the objectID that this node will represent
     */
    public StoreCacheNode(ObjectID id) {
        this.id = id;
    }

    /**
     * Returns the ObjectID represented by this StoreCacheNode.
     *
     * @return the ObjectID represented by this StoreCacheNode
     */
    public ObjectID getID() {
        return id;
    }

    /**
     * Sets the value for the given property. For regular attributes, this will be supported objects like {@link String},
     * {@link Integer}, {@link java.util.Date}, {@link Enum}, etc. For a to-one relationship, the value must be the
     * {@link ObjectID} of the related object. For a to-many relationship, the value must be the a {@code Set<ObjectID>}
     * containing the ObjectIDs of the related objects.
     *
     * @param name  the property name to set
     * @param value the value of the property
     */
    public void setProperty(String name, Object value) {
        properties.put(name, value);
    }

    /**
     * Returns the value of the given property. For regular attributes, this will be supported objects like {@link String},
     * {@link Integer}, {@link java.util.Date}, {@link Enum}, etc. For a to-one relationship, the value must be the
     * {@link ObjectID} of the related object. For a to-many relationship, the value must be the a {@code Set<ObjectID>}
     * containing the ObjectIDs of the related objects.
     *
     * @param name  the property name to get
     *
     * @return the value of the specified property
     */
    public Object getProperty(String name) {
        return properties.get(name);
    }

    /**
     * Returns true if this node is storing a value for the specified property, or false otherwise.
     *
     * @param name  the property name to check
     *
     * @return true if this node is storing a value for the specified property, or false otherwise
     */
    public boolean hasProperty(String name) {
        return properties.containsKey(name);
    }

    /**
     * Returns the key/value store for all the properties in this node.
     *
     * @return the key/value store for all the properties in this node
     */
    public Map<String,Object> getProperties() {
        return properties;
    }
}

@@ -1128,32 +1128,24 @@
 operty. For 
-regular 
 attributes, 
@@ -1142,34 +1142,55 @@
 tributes, th
-is will be
+e value must be of type that is
  supported o
@@ -1183,32 +1183,25 @@
 is supported
- objects
+,
  like %7B@link
@@ -1717,35 +1717,887 @@
 %0A    /**%0A     * 
-R
+S
 et
+s this node to have the properties specified from the input map. Previously set properties in this node will%0A     * be removed.%0A     *%0A     * @param props  a Map containing the key/value pairs for the properties to be set. For keys representing attributes,%0A     *               their value must be of type that is supported, like %7B@link String%7D, %7B@link Integer%7D,%0A     *               %7B@link java.util.Date%7D, %7B@link Enum%7D, etc. For keys representing a to-one relationship, the value%0A     *               must be the %7B@link ObjectID%7D of the related object. For a to-many relationship, the value must be%0A     *               the a %7B@code Set%3CObjectID%3E%7D containing the ObjectIDs of the related objects.%0A     */%0A    public void setProperties(Map%3CString,Object%3E props) %7B%0A        properties.clear();%0A        properties.putAll(props);%0A    %7D%0A%0A    /**%0A     * Ret
 urns the value o
@@ -2624,16 +2624,8 @@
 . Fo
-r regula
 r at
@@ -2636,18 +2636,23 @@
 utes, th
-is
+e value
  will be
@@ -2652,16 +2652,43 @@
 will be 
+of type that is one of the 
 supporte
@@ -2689,22 +2689,20 @@
 pported 
-object
+type
 s like %7B

add method to StoreCacheNode to set all properties