package org.studiorailgun.knowledge;

import org.studiorailgun.Globals;

public class Relation {

    /**
     * The id incremented
     */
    public static int idIncrementer = 0;
    
    /**
     * The id of the relationship
     */
    int id;

    /**
     * Tag of the web that contains this relation
     */
    transient String webTag;

    /**
     * The name of the relationship
     */
    String name;

    /**
     * The parent of the relationship
     */
    int parent;

    /**
     * The web that contains the parent node
     */
    String parentWeb;

    /**
     * The child of the relationship
     */
    int child;

    /**
     * The web that contains this child
     */
    String childWeb;

    /**
     * Constructor
     * @param name The name of the relation
     * @param parent The parent of the relation
     * @param child The child of the relation
     */
    public Relation(String name, Node parent, Node child){
        this.id = idIncrementer;
        idIncrementer++;
        this.name = name;
        this.parent = parent.getId();
        this.child = child.getId();
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public Node getParent() {
        return Globals.web.getNode(this.parent);
    }

    public Node getChild() {
        return Globals.web.getNode(this.child);
    }

    /**
     * Gets the tag for the web the child belongs to (can be null or empty string if the web is the same as the parent)
     * @return The tag for the web
     */
    public String getChildWeb(){
        return this.childWeb;
    }

    /**
     * Gets the tag for the web the parent belongs to (can be null or empty string if the web is the same as the parent)
     * @return The tag for the web
     */
    public String getParentWeb(){
        return this.parentWeb;
    }

    

}
