package pl.designpatterns.behavioral.chainofresponsibility;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.log4j.Logger;

public class ChainOfResponsibilityDemo {

    private static final Logger logger = Logger.getLogger(QuizClient.class);

    public static void main(String[] args) {
        try {
            Askable question1 = new Question("Is CPU a part of PCMCIA?");
            Askable question2 = new Question("Is 'chain of resposibility' a design pattern?");
            Askable question3 = new Question("Is Gabe Newell an alien?");
            Askable question4 = new Question("Are they all lying?");
            List<Askable> questions = new ArrayList<>();
            questions.addAll(Arrays.asList(question1, question2, question3, question4));
            Answers.getInstance().addAnswer(question1.getQuestionString(), false);
            Answers.getInstance().addAnswer(question2.getQuestionString(), true);
            Answers.getInstance().addAnswer(question3.getQuestionString(), false);
            Answers.getInstance().addAnswer(question4.getQuestionString(), true);
            Respondable respondent3 = new Respondent(null);
            Respondable respondent2 = new Respondent(respondent3);
            Respondable respondent1 = new Respondent(respondent2);
            ((Respondent) respondent3).setNextRespondent(respondent1);
            List<Respondable> respondents = new ArrayList<>();
            respondents.addAll(Arrays.asList(respondent1, respondent2, respondent3));
            QuizClient quizClient = new QuizClient(questions, respondents);
            logger.info("Quiz executed in " + quizClient.start() + " ms.");
            logger.info("Quiz scores: " + quizClient.getScores());
        } catch (Exception x) {
            logger.info(x.getMessage());
        }
    }

}
