// Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto.  Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include "TimelineCommon.h"

#include <omni/timeline/ITimeline.h>

#include <OgnTimelineGetDatabase.h>

namespace omni
{
namespace graph
{
namespace nodes
{

class OgnTimelineGet
{
public:
    static bool compute(OgnTimelineGetDatabase& db)
    {
        auto handler = [&db](timeline::TimelinePtr const& timeline)
        {
            db.outputs.isLooping() = timeline->isLooping();
            db.outputs.isPlaying() = timeline->isPlaying();

            double const currentTime = timeline->getCurrentTime();
            double const startTime = timeline->getStartTime();
            double const endTime = timeline->getEndTime();

            db.outputs.time() = currentTime;
            db.outputs.startTime() = startTime;
            db.outputs.endTime() = endTime;

            db.outputs.frame() = timeline->timeToTimeCode(currentTime);
            db.outputs.startFrame() = timeline->timeToTimeCode(startTime);
            db.outputs.endFrame() = timeline->timeToTimeCode(endTime);

            db.outputs.framesPerSecond() = timeline->getTimeCodesPerSecond();

            // TODO: Should we return false when the outputs didn't change?
            return true;
        };

        return timelineNodeEvaluate(db, handler);
    }
};

REGISTER_OGN_NODE()
}
}
}
