#include "classicmode/classicfactory.h"

#include "graphics/classicscenegraphicsmanager.h"
#include "graphics/classictimelinegraphicsmanager.h"
#include "graphics/classicgraphicsfactory.h"

#include "core/timeline.h"
#include "game/classicgame.h"
#include "game/gamecontext.h"
#include "game/holdmanager.h"
#include "editor/classiceditor.h"
#include "editor/editorcontext.h"
#include "editor/selectionmanager.h"


std::unique_ptr<kku::Game> classic::getGame(const std::shared_ptr<kku::CoreFactory>& core_factory)
{
    // read offset from beatmap metadata
    const kku::microsec visibility_offset = 1648648;

    const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
    const auto timeline = std::make_shared<kku::Timeline<ClassicNote>>();
    const auto graphics_manager = std::make_shared<ClassicSceneGraphicsManager>(timeline, factory, visibility_offset);
    const auto hold_manager = std::make_shared<HoldManager>();

    const auto context = std::make_shared<GameContext>(hold_manager, graphics_manager);

    return std::make_unique<ClassicGame>(timeline, context);
}

std::unique_ptr<kku::Editor> classic::getEditor(const std::shared_ptr<kku::CoreFactory>& core_factory)
{
    // read offset from beatmap metadata
    const kku::microsec visibility_offset = 1648648;

    const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
    const auto timeline = std::make_shared<kku::Timeline<ClassicNote>>();
    const auto selection_manager = std::make_shared<SelectionManager<ClassicNote>>();
    std::vector<std::shared_ptr<ClassicGraphicsManager>> graphics_managers;
    graphics_managers.emplace_back(std::make_shared<ClassicSceneGraphicsManager>(timeline, factory, visibility_offset));
    graphics_managers.emplace_back(std::make_shared<ClassicTimelineGraphicsManager>(timeline, factory, visibility_offset * 2));

    const auto context = std::make_shared<EditorContext>(selection_manager, std::move(graphics_managers));

    return std::make_unique<ClassicEditor>(timeline, context);
}
