package org.studiorailgun.ai.conversation.web;

import java.util.LinkedList;
import java.util.List;

import org.studiorailgun.Globals;
import org.studiorailgun.ai.knowledge.Node;
import org.studiorailgun.ai.knowledge.query.filter.NameQueryFilter;

/**
 * Queries for nodes related to conversations
 */
public class ConversationQuery {

    /**
     * Gets the current conversation
     * @return The current conversation
     */
    public static Node getCurrentConversation(){
        List<Node> nodes = new LinkedList<Node>(Globals.web.getNodes());
        return NameQueryFilter.withNodeName(nodes, "CurrentConversation");
    }
    
    /**
     * Gets the node for the other participant in the conversation
     * @return The other participant in the conversation
     */
    public static Node getOtherParticipant(){
        List<Node> nodes = new LinkedList<Node>(Globals.web.getNodes());
        return NameQueryFilter.withNodeName(nodes, "Other");
    }

    /**
     * Adds a quote to the conversation
     * @param speaker The speaker of the quote
     * @param quote The quote
     */
    public static void addQuote(Node speaker, Node quote){
        //relate this node to the speaker
        QuoteQuery.assignSpeaker(speaker, quote);
        //relate this node to the conversation
        QuoteQuery.assignConversation(ConversationQuery.getCurrentConversation(), quote);
    }

}
