package de.thdeg.greiner.superpangworld.game.managers;

import de.thdeg.greiner.superpangworld.graphics.helper.Level;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * The level manager for creating and providing levels.
 */
public class LevelManager {

    /** The queue to store the generated levels */
    private final Queue<Level> levels;

    /**
     * Create a level manager.
     *
     * @param easyDifficulty the difficulty
     */
    public LevelManager(boolean easyDifficulty){
        levels = new ArrayDeque<>();
        generateLevels(easyDifficulty);
    }

    /**
     * Get the next level. If there a no remaining levels an exception is thrown.
     *
     * @return the next level
     * @throws NoMoreLevelsAvailableException if there is no level remaining
     */
    public Level getNextLevel() throws NoMoreLevelsAvailableException {
        if(levels.isEmpty()){
            throw new NoMoreLevelsAvailableException();
        }else{
            return levels.poll();
        }
    }

    /**
     * Generate the levels according to the difficulty.
     *
     * @param easyDifficulty the difficulty
     */
    private void generateLevels(boolean easyDifficulty){
        int overallScoreNeeded = 0;
        for(int i=0;i<3;i++){
            int scoreNeeded = easyDifficulty ? 1000 + (100*i) : 10000 + (1000*i);
            overallScoreNeeded += scoreNeeded;
            levels.add(new Level(i+1, scoreNeeded,overallScoreNeeded));
        }
    }

    /**
     * The exception in case no next level is remaining.
     */
    public static class NoMoreLevelsAvailableException extends Exception{}
}
