/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014, Regents of the University of California.
 *
 * This file is part of NDNS (Named Data Networking Domain Name Service).
 * See AUTHORS.md for complete list of NDNS authors and contributors.
 *
 * NDNS 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.
 *
 * NDNS 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
 * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef NDNS_RRSET_HPP
#define NDNS_RRSET_HPP

#include "zone.hpp"

namespace ndn {
namespace ndns {

/**
 * @brief Resource Record Set (rrset) define the the entry's attributes in NDNS
 *        this class also reflects the table (rrset) schema in the database
 *
 * The class is copyable, since it may be assigned to another Rrset instance
 * when resolving Response or Query from database
 */
class Rrset
{
public:
  explicit
  Rrset(Zone* zone = 0);

  /**
   * @brief get the id
   *
   * Default value is 0, the database has to guarantee that id is greater than 0.
   */
  uint64_t
  getId() const
  {
    return m_id;
  }

  /**
   * @brief set the id
   *
   * Default value is 0, the database has to guarantee that id is greater than 0.
   */
  void
  setId(uint64_t id)
  {
    m_id = id;
  }

  /**
   * @brief get the zone where the record is stored
   */
  Zone*
  getZone() const
  {
    return m_zone;
  }

  /**
   * @brief set the zone where the record is stored
   */
  void
  setZone(Zone* zone)
  {
    m_zone = zone;
  }

  /**
   * @brief get the label of rrset
   */
  const Name&
  getLabel() const
  {
    return m_label;
  }

  /**
   * @brief set the label of rrset
   */
  void
  setLabel(const Name& label)
  {
    m_label = label;
  }

  /**
   * @brief get the type of this rrset
   */
  const name::Component&
  getType() const
  {
    return m_type;
  }

  /**
   * @brief set the type of this rrset
   */
  void
  setType(const name::Component& type)
  {
    m_type = type;
  }

  /**
   * @brief get version of the data
   */
  const name::Component&
  getVersion() const
  {
    return m_version;
  }

  /**
   * @brief set version of the rrset
   */
  void
  setVersion(const name::Component& version)
  {
    m_version = version;
  }

  /**
   * @brief get ttl of the rrset
   */
  const time::seconds&
  getTtl() const
  {
    return m_ttl;
  }

  /**
   * @brief set ttl of the rrset
   */
  void
  setTtl(const time::seconds& ttl)
  {
    m_ttl = ttl;
  }

  /**
   * @brief get wire formatted block of the Response
   */
  const Block&
  getData() const
  {
    return m_data;
  }

  /**
   * @brief set wire formatted block of the Response
   */
  void
  setData(const Block& data)
  {
    m_data = data;
  }

  /**
   * @brief compare two rrset instance
   *
   * Note that comparison ignores id, TTL, and Data when comparing RR sets
   */
  bool
  operator==(const Rrset& other) const
  {
    return (getZone() == other.getZone() && getLabel() == other.getLabel() &&
            getType() == other.getType() && getVersion() == other.getVersion());
  }

  /**
   * @brief compare two rrset instance
   *
   * Note that comparison ignores id, TTL, and Data when comparing RR sets
   */
  bool
  operator!=(const Rrset& other) const
  {
    return !(*this == other);
  }

private:
  uint64_t m_id;
  Zone* m_zone;
  Name m_label;
  name::Component m_type;
  name::Component m_version;
  time::seconds m_ttl;
  Block m_data;
};

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

} // namespace ndns
} // namespace ndn

#endif // NDNS_RRSET_HPP
