package org.studiorailgun.conversation.tracking;

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

import org.studiorailgun.conversation.evaluators.goal.GoalData;
import org.studiorailgun.conversation.evaluators.greet.GreetingData;
import org.studiorailgun.knowledge.KnowledgeWeb;
import org.studiorailgun.knowledge.Node;

/**
 * A conversation
 */
public class Conversation {
    
    /**
     * The self instance
     */
    ConvParticipant self;

    /**
     * The other participant in the conversation
     */
    ConvParticipant other;

    /**
     * The node in the knowledge web representing this conversation
     */
    Node data;

    /**
     * Data on greetings
     */
    GreetingData greetingData;

    /**
     * The goal data
     */
    GoalData goalData;

    /**
     * The history of the conversation
     */
    List<Quote> history;

    /**
     * Parses the current conversation's data from the knowledge web
     * @param web The web
     * @return The conversation
     */
    public static Conversation parse(KnowledgeWeb web){
        Node node = web.getNode(7);

        //find the self
        ConvParticipant self = new ConvParticipant(web.getAnchors().getSelfNode());

        //find the other participant
        ConvParticipant other = new ConvParticipant(web.getNode(4));

        Conversation rVal = new Conversation(node, self, other);
        return rVal;
    }

    /**
     * Constructor
     * @param node The node representing this conversation instance
     * @param self The participant representing this bot instance
     * @param other The participant representing the other party in the conversation
     */
    public Conversation(Node node, ConvParticipant self, ConvParticipant other){
        this.data = node;
        this.self = self;
        this.other = other;
        this.greetingData = new GreetingData();
        this.goalData = new GoalData();
        this.history = new LinkedList<Quote>();
    }

    /**
     * Gets the greeting data
     * @return The greeting data
     */
    public GreetingData getGreetingData(){
        return greetingData;
    }

    /**
     * Gets the self
     * @return The self
     */
    public ConvParticipant getSelf(){
        return self;
    }

    /**
     * Gets the other
     * @return The other
     */
    public ConvParticipant getOther(){
        return other;
    }

    public GoalData getGoalData() {
        return goalData;
    }

    public void setGoalData(GoalData goalData) {
        this.goalData = goalData;
    }

    /**
     * Gets the history of the conversation
     * @return The history of the conversation
     */
    public List<Quote> getHistory(){
        return history;
    }

    /**
     * Adds a quote to the conversation
     * @param quote The quote
     */
    public void addQuote(Quote quote){
        this.history.add(quote);
    }

    

}
