#include "classicmapcreator.h"
#include "classicarrownote.h"
#include "gamecontext.h"

// Replace with interface by dependency injection
#include "graphics/animations/classicflyinganimationscenario.h"
#include "graphics/animations/classicdyinganimationscenario.h"
//

auto classic::createBeatmap(const std::string& filepath, const std::shared_ptr<GameContext>& context) -> Beatmap
{
    (void) filepath;

    kku::microsec starting_beat_offset = 402162;
    int amount_of_beats = 209;
    kku::microsec interval = 1412162;
    kku::microsec tempo_interval = interval / 4;
    kku::microsec note_input_offset = 412162 / 2;
    //microsec note_input_offset_fast = 412162 / 6;
    kku::microsec bpm_iterator = starting_beat_offset;
    kku::microsec bpm_end = starting_beat_offset + (interval * amount_of_beats);

    std::vector<kku::microsec> input_intervals = {note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset};
    std::set<ClassicNote*, kku::NotePtrComparator> notes;
    input_intervals.shrink_to_fit();

    bpm_iterator += tempo_interval;

    float x = 90.;

    int counter = 3;

    int id = 0;
    while (bpm_iterator < bpm_end)
    {
        ArrowElement element;

        element.position = kku::Point(x, 390.f);
        element.falling_curve_interpolation = {};

        element.keys = {kku::SystemEvent::Key::Code::W,
                        kku::SystemEvent::Key::Code::Up};

        element.type = Type::UP;

        bool hold = false;

        if (counter == 0)
        {
            hold = true;

            element.keys = {kku::SystemEvent::Key::Code::D,
                            kku::SystemEvent::Key::Code::Right};

            element.type = Type::RIGHT;

            counter = 13;
        }

        --counter;

        ClassicArrowNote::Init init
        {
            id++,
            context,
            bpm_iterator,
            input_intervals,
            {element},
            hold
        };

        notes.insert(new ClassicArrowNote(std::move(init)));

        bpm_iterator += tempo_interval;
        x += 70;

        if (x >= 1200)
            x = 90.;
    }

    return {std::move(notes), note_input_offset * 8};
}

