#pragma once

#include "core/precisionevaluator.h"
#include "classicmode/classicnote.h"
#include "game/arrowelement.h"

#include <algorithm>

class Context;

class ClassicArrowNote : public ClassicNote
{
public:

    struct Init
    {
        const int id = 0;
        const std::shared_ptr<const Context> context;
        const kku::microsec perfect_offset = 0;

        const std::vector<kku::microsec>& intervals = {};
        const std::vector<ArrowElement>& elements = {};

        const bool is_holding = false;
    };

    enum class Grade
    {
        PERFECT = 0,
           GOOD = 1,
            BAD = 2
    };

    explicit ClassicArrowNote(Init&& init);

    virtual bool isActive(const kku::microsec& offset) const override;
    virtual void update(const kku::microsec &music_offset) override;
    virtual void input(kku::GameEvent&& input) override;
    virtual void draw(const std::shared_ptr<const ClassicGraphicsManager> &graphics_manager) const override;

    bool isHold() const;
    std::vector<ArrowElement>& getElements();
    Grade calculatePrecision(const kku::microsec& offset) const;
    bool isPressedAs(kku::SystemEvent::Key::Code key) const;

private:
    const kku::PrecisionEvaluator<Grade> _evaluator;
    std::vector<ArrowElement> _elements;
    const std::shared_ptr<const Context> _context;

    bool _is_holding;
};
