/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2024,  Regents of the University of California,
 *                           Arizona Board of Regents,
 *                           Colorado State University,
 *                           University Pierre & Marie Curie, Sorbonne University,
 *                           Washington University in St. Louis,
 *                           Beijing Institute of Technology,
 *                           The University of Memphis.
 *
 * This file is part of NFD (Named Data Networking Forwarding Daemon).
 * See AUTHORS.md for complete list of NFD authors and contributors.
 *
 * NFD is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef NFD_DAEMON_RIB_ROUTE_HPP
#define NFD_DAEMON_RIB_ROUTE_HPP

#include "core/common.hpp"

#include <ndn-cxx/encoding/nfd-constants.hpp>
#include <ndn-cxx/mgmt/nfd/route-flags-traits.hpp>
#include <ndn-cxx/prefix-announcement.hpp>
#include <ndn-cxx/util/scheduler.hpp>

#include <type_traits>

namespace nfd::rib {

/**
 * \brief Represents a route for a name prefix.
 */
class Route : public ndn::nfd::RouteFlagsTraits<Route>, private boost::equality_comparable<Route>
{
public:
  /** \brief Default constructor.
   */
  Route();

  /** \brief Construct from a prefix announcement.
   *  \param ann a prefix announcement that has passed verification
   *  \param faceId the face on which \p ann arrived
   */
  Route(const ndn::PrefixAnnouncement& ann, uint64_t faceId);

  const ndn::scheduler::EventId&
  getExpirationEvent() const
  {
    return m_expirationEvent;
  }

  void
  setExpirationEvent(const ndn::scheduler::EventId& eid)
  {
    m_expirationEvent = eid;
  }

  void
  cancelExpirationEvent()
  {
    m_expirationEvent.cancel();
  }

  std::underlying_type_t<ndn::nfd::RouteFlags>
  getFlags() const
  {
    return flags;
  }

public: // non-member operators (hidden friends)
  friend bool
  operator==(const Route& lhs, const Route& rhs)
  {
    return lhs.faceId == rhs.faceId &&
           lhs.origin == rhs.origin &&
           lhs.cost == rhs.cost &&
           lhs.flags == rhs.flags &&
           lhs.expires == rhs.expires &&
           lhs.announcement == rhs.announcement;
  }

public:
  uint64_t faceId = 0;
  ndn::nfd::RouteOrigin origin = ndn::nfd::ROUTE_ORIGIN_APP;
  uint64_t cost = 0;
  std::underlying_type_t<ndn::nfd::RouteFlags> flags = ndn::nfd::ROUTE_FLAGS_NONE;
  std::optional<time::steady_clock::time_point> expires;

  /** \brief The prefix announcement that caused the creation of this route.
   *
   *  This is nullopt if this route is not created by a prefix announcement.
   */
  std::optional<ndn::PrefixAnnouncement> announcement;

  /** \brief Expiration time of the prefix announcement.
   *
   *  Valid only if announcement is not nullopt.
   *
   *  If this field is before or equal the current time, it indicates the prefix announcement is
   *  not yet valid or has expired. In this case, the exact value of this field does not matter.
   *  If this field is after the current time, it indicates when the prefix announcement expires.
   */
  time::steady_clock::time_point annExpires;

private:
  ndn::scheduler::EventId m_expirationEvent;
};

std::ostream&
operator<<(std::ostream& os, const Route& route);

} // namespace nfd::rib

#endif // NFD_DAEMON_RIB_ROUTE_HPP
