package org.studiorailgun.ai.conversation.evaluators.goal;

import org.studiorailgun.ai.conversation.evaluators.goal.GoalData.ConversationGoal;
import org.studiorailgun.ai.conversation.evaluators.greet.GreetingData;
import org.studiorailgun.ai.conversation.evaluators.query.QueryData;
import org.studiorailgun.ai.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();

        //evaluate if goal should be to greet
        if(!greetingData.getHaveGreeted().contains(conversation.getSelf())){
            goalData.setGoal(ConversationGoal.GREET);
            return;
        }

        //evaluate if goal should be to answer a question
        if(queryData.getRecentQueries().size() > 0){
            goalData.setGoal(ConversationGoal.ANSWER);
            return;
        }

        //try to open a conversation with a question
        if(SmallTalkEval.shouldPursueSmalltalk(goalData)){
            goalData.setGoal(ConversationGoal.OPENER);
            return;
        }

        //if failed to find a goal, set current goal to null
        conversation.getGoalData().setGoal(null);
    }

}
