package com.mygdx.game;

import java.util.Random;

public class MathProblem {
    String question;
    int answer;

    public MathProblem(String question, int answer) {
        this.question = question;
        this.answer = answer;
    }

    public static MathProblem generateProblem(int difficulty, Random random) {
        int a, b, c;
        String question;
        int answer;

        if (difficulty < 2) {
            a = 1 + random.nextInt(20);
            b = 1 + random.nextInt(20);
            if (random.nextBoolean()) {
                question = a + " + " + b + " = ?";
                answer = a + b;
            } else {
                if (a < b) {
                    int temp = a;
                    a = b;
                    b = temp;
                }
                question = a + " - " + b + " = ?";
                answer = a - b;
            }
        } else if (difficulty < 4) {
            a = 2 + random.nextInt(9);
            b = 2 + random.nextInt(9);
            question = a + " × " + b + " = ?";
            answer = a * b;
        } else if (difficulty < 6) {
            a = 1 + random.nextInt(10);
            b = 1 + random.nextInt(10);
            c = 2 + random.nextInt(8);
            question = "(" + a + " + " + b + ") × " + c + " = ?";
            answer = (a + b) * c;
        } else {
            b = 2 + random.nextInt(4);
            c = 2 + random.nextInt(4);
            int multiplication = b * c;
            a = multiplication + random.nextInt(10) + 5;
            question = a + " - " + b + " × " + c + " = ?";
            answer = a - multiplication;
        }

        return new MathProblem(question, answer);
    }

    public String getQuestion() { return question; }
    public int getAnswer() { return answer; }
}
