#ifndef PERF_TIMELINE_HPP_
#define PERF_TIMELINE_HPP_

#include <chrono>
#include <vector>

#include <ThreadClock/ThreadClock.hpp>

using namespace std::chrono_literals;

/**
 * @brief Represents the timeline of performance events.
 */
class PerfTimeline
{
private:
    std::chrono::time_point<std::chrono::steady_clock> startPoint;
    ThreadClock threadClock;

public:
    typedef std::chrono::steady_clock::duration Ticks;

    class Interval
    {
    public:
        std::chrono::steady_clock::duration start;
        std::chrono::steady_clock::duration end;

        ThreadClock::Duration threadStart;
        ThreadClock::Duration threadEnd;
    };

    class Event
    {
    private:
        PerfTimeline &timeline;
        std::vector<Interval> intervalList;
        std::chrono::steady_clock::duration startTime;
        ThreadClock::Duration threadStartTime;

    public:
        Event(PerfTimeline &timeline);

        /**
         * @brief Start this event.
         */
        void start();

        /**
         * @brief End this event.
         */
        void end();

        /**
         * @brief Reset this event.
         */
        void reset();

        /**
         * @brief Get the intervals of this event.
         */
        const std::vector<Interval>& intervals() const;
    };

    #define DECL_PERF_EVENT(name, ...) Event name;
    #include <PerfTimeline/PerfEventList.hpp>

    int ignore;

    PerfTimeline();

    /**
     * @brief Reset this timeline.
     */
    void reset();

    /**
     * @brief Get the current duration of this timeline.
     */
    Ticks getCurrentDuration();

    friend class PerfTimeline::Event;
};

#endif