import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Question {
    public String text;
    public List<Answer> answers;
    public List<Answer> correctAnswers;
    
    // Constructor
    public Question(String text, List<Answer> answers, List<Answer> correctAnswers) {
        this.text = text;
        this.answers = answers;
        this.correctAnswers = correctAnswers;
    }
    
    public void askQuestion() {
        // Print the question text
        System.out.println(this.text);
        
        // Print the answers with enumerated labels
        char option = 'a';
        for (Answer answer : this.answers) {
            System.out.println(option + ") " + answer.text);
            option++;
        }
        
        // Prompt the user for an answer
        System.out.print("Enter your answer (e.g., 'ad' for answers a) and d)): ");
        Scanner scanner = new Scanner(System.in);
        String userInput = scanner.nextLine().toLowerCase();
        
        // Process the user input
        if (validateAnswer(userInput)) {
            System.out.println("Correct!");
        } else {
            System.out.println("Incorrect.");
        }
        scanner.close();
    }
    
    private boolean validateAnswer(String userInput) {
        // Convert the user input into a set of expected correct answers
        char[] userAnswers = userInput.toCharArray();
        List<Answer> selectedAnswers = new ArrayList<>();
        
        for (char option : userAnswers) {
            int index = option - 'a'; // Convert 'a', 'b', etc., to 0, 1, etc.
            if (index >= 0 && index < this.answers.size()) {
                selectedAnswers.add(this.answers.get(index));
            }
        }
        
        // Check if the selected answers match the correct answers
        return selectedAnswers.containsAll(this.correctAnswers) && this.correctAnswers.containsAll(selectedAnswers);
    }
    
}
