package org.studiorailgun.conversation.evaluators.goal;

import org.studiorailgun.conversation.evaluators.goal.GoalData.ConversationGoal;
import org.studiorailgun.conversation.evaluators.greet.GreetingData;
import org.studiorailgun.conversation.evaluators.query.QueryData;
import org.studiorailgun.conversation.tracking.ConvParticipant;
import org.studiorailgun.conversation.tracking.Conversation;

/**
 * Evaluates the AI's goal in the conversation
 */
public class GoalEval {
    

    /**
     * Evaluates the goal of the ai in the given conversation
     * @param conversation The conversation
     */
    public static void evaluate(Conversation conversation){
        GreetingData greetingData = conversation.getGreetingData();
        GoalData goalData = conversation.getGoalData();
        QueryData queryData = goalData.getQueryData();
        ConvParticipant selfParticipant = conversation.getSelf();

        boolean set = false;

        //evaluate if goal should be to greet
        if(!greetingData.getHaveGreeted().contains(selfParticipant)){
            conversation.getGoalData().setGoal(ConversationGoal.GREET);
            set = true;
        }

        //evaluate if goal should be to answer a question
        if(queryData.getRecentQueries().size() > 0){
            conversation.getGoalData().setGoal(ConversationGoal.ANSWER);
            set = true;
        }

        if(!set){
            throw new Error("Failed to find a goal to pursue in the conversation!");
        }
    }

}
