package fr.uge.concurrence.exo2;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;

public class LLMSimulator {

    public enum LLM {
        CHATGPT, BARD, CLAUDE, LLAMA
    }

    private static final List<String> QUESTIONS = List.of(
            "Why does my code work only after I reboot the universe?",
            "How do I make my variable names more self-explanatory than 'x' and 'y'?",
            "Why does my app only crash during demos?",
            "How do I make my print statements stop causing side effects?",
            "Why does 'null' keep sneaking into my code like a ninja?",
            "Can I blame the compiler for my logic errors?",
            "Why does my CSS obey rules only when I add '!important' everywhere?",
            "Why does 'Works on My Machine' never work on anyone else's machine?",
            "How do I convince my code to respect me as its creator?",
            "Why does my recursive function feel like a prank from future me?",
            "Is there a debugger that understands my sarcasm?",
            "Why does my loop work perfectly until it encounters the number 42?",
            "Can I file a restraining order against bugs in my code?",
            "Why do semicolons disappear when I’m not looking?",
            "How do I stop my regex from solving world hunger before it solves my problem?",
            "Why does the error log look like it’s written in Klingon?",
            "How do I explain to my manager that 'optimization' isn't just a magic button?",
            "Why do my test cases pass only on Friday the 13th?",
            "Why does my code run perfectly on Stack Overflow but fail on my machine?",
            "Can I declare a variable that automatically makes me a better programmer?"
    );

    private static final List<String> ANSWERS = List.of(
            "Have you tried consulting the sacred scrolls of documentation?",
            "The answer lies in the hidden wisdom of the user guide.",
            "The solution is probably written in the stars—or the manual.",
            "Legends say the instructions hold all the secrets you seek.",
            "If only someone had written down how to do this... oh wait.",
            "The oracle of documentation awaits your query.",
            "Your answers are just a page flip away in the guide.",
            "Maybe the author of the docs was trying to tell us something.",
            "The knowledge you need has been hiding in plain sight.",
            "There's a scroll called 'Instructions.' Start there.",
            "I sense the solution is inscribed in a forgotten tome.",
            "It’s amazing what mysteries the help section can unveil.",
            "Somewhere, a lonely manual knows the answer to this.",
            "Maybe try deciphering the sacred text of the guide.",
            "If you whisper to the docs, they might respond.",
            "The ancient wisdom of troubleshooting suggests reading the guide.",
            "There's a prophecy that says the manual has the answer.",
            "Consult the mighty codex of user instructions.",
            "Have you considered befriending the documentation?",
            "The sacred texts contain the enlightenment you seek.",
            "RTFM",
            "RTFM!!!"
    );


    public record Question(String content, LLM llm) {
        public Question {
            Objects.requireNonNull(content);
            Objects.requireNonNull(llm);
        }
    }

    public record Answer(String question, String answer, LLM llm) {
        public Answer {
            Objects.requireNonNull(question);
            Objects.requireNonNull(answer);
            Objects.requireNonNull(llm);
        }
    }

    /**
     * Simulate the retrieval of a question from a user to a given LLM
     *
     * @return a Question object
     */
    public static Question retrieveQuestion() throws InterruptedException {
        Thread.sleep(500);
        String randomQuestion = QUESTIONS.get(ThreadLocalRandom.current().nextInt(QUESTIONS.size()));
        LLM randomLLM = LLM.values()[ThreadLocalRandom.current().nextInt(LLM.values().length)];
        return new Question(randomQuestion, randomLLM);
    }

    /**
     * Generates the answer for the given question with the appropriate LLM
     *
     * @param question the Question object
     * @return an Answer object
     */
    public static Answer createAnswer(Question question) throws InterruptedException {
        Thread.sleep(2000);
        String randomAnswer = ANSWERS.get(ThreadLocalRandom.current().nextInt(ANSWERS.size()));
        return new Answer(question.content(), randomAnswer, question.llm());
    }

    /**
     * Test if an answer should be censored
     *
     * @param answer
     * @return if the answer should be censored
     * @throws InterruptedException
     */

    public static boolean shouldCensor(Answer answer) throws InterruptedException {
        Thread.sleep(1000);
        return answer.answer.contains("RTFM");
    }



}



