// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef REAF_CLOCK_H_
#define REAF_CLOCK_H_

#include <chrono>

#include <absl/time/time.h>

namespace reaf {
class Clock {
 public:
  // Returns a pointer to the global realtime clock.  The caller does not
  // own the returned pointer and should not delete it.  The returned clock
  // is thread-safe.
  static Clock *RealClock();

  virtual ~Clock();

  // Returns the current time.
  virtual absl::Time TimeNow() = 0;

  // Sleeps until the specified time.
  virtual void SleepUntil(absl::Time wakeup_time) = 0;
};

class MonotonicClock : public Clock {
 public:
  MonotonicClock();
  ~MonotonicClock() override;

  // Returns the current time.
  absl::Time TimeNow() override;

  // Sleeps until the specified time.
  // Only pass times generated by this clock TimeNow function.
  void SleepUntil(absl::Time wakeup_time) override;

 private:
  absl::Time steady_clock_epoch_;
};

}  // namespace reaf

#endif  //  REAF_CLOCK_H_
