package de.frajul.endlessroll.main.tutorial;

import de.frajul.endlessroll.R;
import de.frajul.endlessroll.entities.tools.ToolType;
import de.frajul.endlessroll.levels.Level;
import de.frajul.endlessroll.main.GameActivity;
import de.frajul.endlessroll.user.User;
import de.frajul.endlessroll.views.TopBar;

/**
 * Created by Julian on 17.03.2017.
 */

public class TutorialManager {

    private final int WELCOME_TUTORIAL_LEVEL = 1;
    private final int IN_AIR_TUTORIAL_LEVEL = 5;
    private final int SWITCH_TOOLS_TUTORIAL_LEVEL = 10;

    private Tutorial welcomeTutorial;
    private Tutorial inAirTutorial;
    private Tutorial toToolShopTutorial;
    private ToolShopTutorial toolShopTutorial;
    private Tutorial switchToolsTutorial;

    public TutorialManager(GameActivity gameActivity) {
        welcomeTutorial = new Tutorial(gameActivity,
                new BreakPoint(0, R.string.tutorial_welcome, -1),
                new BreakPoint(0, R.string.tutorial_place_tools, R.drawable.tutorial_place_tools),
                new BreakPoint(7, R.string.tutorial_place_ramp_gap,
                        R.drawable.tutorial_place_ramp_gap),
                new BreakPoint(21, R.string.tutorial_place_ramp_obstacle,
                        R.drawable.tutorial_place_ramp_obstacle));
        inAirTutorial = new Tutorial(gameActivity,
                new BreakPoint(11, R.string.tutorial_place_ramp_air,
                        R.drawable.tutorial_place_ramp_air_1),
                new BreakPoint(33, R.string.tutorial_place_ramp_air_2,
                        R.drawable.tutorial_place_ramp_air_2));
        toToolShopTutorial = new Tutorial(gameActivity,
                new BreakPoint(BreakPoint.NONE_X, R.string.tutorial_leveled_up_to_toolshop,
                        R.drawable.tutorial_to_toolshop));
        toolShopTutorial = new ToolShopTutorial(gameActivity);
        switchToolsTutorial = new Tutorial(gameActivity,
                new BreakPoint(0, R.string.tutorial_switch_tools_two_neccessary, -1),
                new BreakPoint(0, R.string.tutorial_switch_tools_switch, R.drawable.tutorial_switch_tools));
    }

    public void update(Level level, float playerProgress) {
        if (level.getPackId() == 1 && level.getId() == WELCOME_TUTORIAL_LEVEL && !level
                .isFinished()) {
            welcomeTutorial.update(playerProgress);
        } else if (level.getPackId() == 1 && level.getId() == IN_AIR_TUTORIAL_LEVEL && !level
                .isFinished()) {
            inAirTutorial.update(playerProgress);
        } else if (level.getPackId() == 1 && level.getId() == SWITCH_TOOLS_TUTORIAL_LEVEL && !level
                .isFinished()) {
            switchToolsTutorial.update(playerProgress);
        }
    }

    public void onLvUp(User user) {
        boolean springUnlockedOnLvUp = user.getLevelUpBounties()
                .getLevelToolIsUnlocked(ToolType.SPRING) == user.getLevel();
        if (springUnlockedOnLvUp) {
            toToolShopTutorial.showAllBreakPoints();
        }
    }

    public void onTopBarUpdate(TopBar topBar) {
        toolShopTutorial.onTopBarUpdate(topBar);
    }

    public void resetGameTutorials() {
        welcomeTutorial.reset();
        inAirTutorial.reset();
        switchToolsTutorial.reset();
    }

    public void resetAllTutorials() {
        welcomeTutorial.reset();
        inAirTutorial.reset();
        switchToolsTutorial.reset();
        toToolShopTutorial.reset();
        toolShopTutorial.setFinished(false);
    }

    public ToolShopTutorial getToolShopTutorial() {
        return toolShopTutorial;
    }
}
