/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2017-2020, Regents of the University of California.
 *
 * This file is part of ndncert, a certificate management system based on NDN.
 *
 * ndncert 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.
 *
 * ndncert 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 copies of the GNU General Public License along with
 * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 *
 * See AUTHORS.md for complete list of ndncert authors and contributors.
 */

#ifndef NDNCERT_CA_STORAGE_HPP
#define NDNCERT_CA_STORAGE_HPP

#include "ca-detail/ca-state.hpp"

namespace ndn {
namespace ndncert {

class CaStorage : noncopyable
{
public: // request related
  /**
   * @throw if request cannot be fetched from underlying data storage
   */
  virtual CaState
  getRequest(const std::string& requestId) = 0;

  /**
   * @throw if there is an existing request with the same request ID
   */
  virtual void
  addRequest(const CaState& request) = 0;

  virtual void
  updateRequest(const CaState& request) = 0;

  virtual void
  deleteRequest(const std::string& requestId) = 0;

  virtual std::list<CaState>
  listAllRequests() = 0;

  virtual std::list<CaState>
  listAllRequests(const Name& caName) = 0;

public: // factory
  template<class CaStorageType>
  static void
  registerCaStorage(const std::string& caStorageType = CaStorageType::STORAGE_TYPE)
  {
    CaStorageFactory& factory = getFactory();
    BOOST_ASSERT(factory.count(caStorageType) == 0);
    factory[caStorageType] = [] (const Name& caName, const std::string& path) {
      return std::make_unique<CaStorageType>(caName, path);
    };
  }

  static unique_ptr<CaStorage>
  createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path);

  virtual
  ~CaStorage() = default;

private:
  using CaStorageCreateFunc = function<unique_ptr<CaStorage> (const Name&, const std::string&)>;
  using CaStorageFactory = std::map<std::string, CaStorageCreateFunc>;

  static CaStorageFactory&
  getFactory();
};

#define NDNCERT_REGISTER_CA_STORAGE(C)                           \
static class NdnCert ## C ## CaStorageRegistrationClass          \
{                                                                \
public:                                                          \
  NdnCert ## C ## CaStorageRegistrationClass()                   \
  {                                                              \
    ::ndn::ndncert::CaStorage::registerCaStorage<C>();           \
  }                                                              \
} g_NdnCert ## C ## CaStorageRegistrationVariable

} // namespace ndncert
} // namespace ndn

#endif // NDNCERT_CA_STORAGE_HPP
