package org.studiorailgun;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;
import org.studiorailgun.ai.conversation.ConvAI;
import org.studiorailgun.ai.conversation.categorization.SentenceFunctionCategorizor;
import org.studiorailgun.ai.conversation.evaluators.greet.GreetingEval;
import org.studiorailgun.ai.conversation.evaluators.query.QueryData;
import org.studiorailgun.ai.conversation.evaluators.query.QueryEval;
import org.studiorailgun.ai.conversation.parser.NLPParser;
import org.studiorailgun.ai.conversation.tracking.Conversation;
import org.studiorailgun.ai.conversation.tracking.Quote;
import org.studiorailgun.ai.conversation.tracking.Sentence;
import org.studiorailgun.ai.conversation.web.ConversationQuery;

/**
 * Query tests
 */
public class QueryTests {
    
    @Test
    public void testOtherGreeting(){
        Globals.init("./data/webs/test/web.json");
        
        Quote response = ConvAI.simFrame("What color is your hat?");

        boolean responseContainsBlue = response.getRaw().contains("blue");
        assertEquals(responseContainsBlue, true);
    }


    @Test
    public void testQueryEval(){
        Globals.init("./data/webs/test/web.json");

        //Linguistics structures
        Conversation conversation = Globals.conversation;
        Quote quote = new Quote("What color is your hat?");

        //perform NLP evaluation of the quote
        NLPParser.parse(quote);

        //parse data about the quote
        for(Sentence sentence : quote.getSentences()){
            SentenceFunctionCategorizor.categorize(sentence);
        }

        //add the quote to the conversation
        conversation.addQuote(ConversationQuery.getOtherParticipant(), quote);

        //evaluate each sentence
        for(Sentence sentence : quote.getSentences()){
            switch(sentence.getFunction()){
                case UTILITY: {
                    GreetingEval.evaluate(conversation, quote, sentence);
                } break;
                case QUERY: {
                    QueryEval.evaluate(conversation, quote, sentence);
                } break;
                default: {
                    throw new UnsupportedOperationException("Unsupported quote function: " + sentence.getFunction());
                }
            }
        }
        QueryData queryData = Globals.conversation.getGoalData().getQueryData();
        assertEquals(queryData.getRecentQueries().size(), 1);
    }

}
