#include "Application.h"
#include "States/SelectState.h"

#include <iostream>

Application::Application(): m_ptr_state_current(std::make_unique<SelectState>
        (*this, config::SELECT_LEVEL_VIDEO_MODE, config::SELECT_LEVEL_TITLE)) {}

void Application::set_next_state(std::unique_ptr<IState>&& ptr_state) {
    m_ptr_state_next = std::move(ptr_state);
}

void Application::apply_differ_state_change() noexcept {
    if (m_ptr_state_next)
        m_ptr_state_current = std::move(m_ptr_state_next);
}

int Application::run() {
    try {
        while (m_ptr_state_current->do_step())
            apply_differ_state_change();
    }
    catch (std::exception& ex) {
        std::cout << ex.what() << '\n';
        return 1;
    }
    catch (...) {
        std::cout << "Unknown exception\n";
        return 2;
    }
    return 0;
}