/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2017-2022, 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_CHALLENGE_MODULE_HPP
#define NDNCERT_CHALLENGE_MODULE_HPP

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

#include <map>

namespace ndncert {

class ChallengeModule : boost::noncopyable
{
public:
  ChallengeModule(const std::string& challengeType, size_t maxAttemptTimes, time::seconds secretLifetime);

  virtual
  ~ChallengeModule() = default;

  // For CA
  virtual std::tuple<ErrorCode, std::string>
  handleChallengeRequest(const Block& params, ca::RequestState& request) = 0;

  // For Client
  virtual std::multimap<std::string, std::string>
  getRequestedParameterList(Status status, const std::string& challengeStatus) = 0;

  virtual Block
  genChallengeRequestTLV(Status status, const std::string& challengeStatus,
                         const std::multimap<std::string, std::string>& params) = 0;

public: // factory
  template<class ChallengeType>
  static void
  registerChallengeModule(const std::string& type)
  {
    auto& factory = getFactory();
    BOOST_ASSERT(factory.count(type) == 0);
    factory[type] = [] { return std::make_unique<ChallengeType>(); };
  }

  static bool
  isChallengeSupported(const std::string& challengeType);

  static std::unique_ptr<ChallengeModule>
  createChallengeModule(const std::string& challengeType);

protected: // helpers used by concrete challenge modules
  static std::string
  generateSecretCode();

  static std::tuple<ErrorCode, std::string>
  returnWithError(ca::RequestState& request, ErrorCode errorCode, std::string errorInfo);

  std::tuple<ErrorCode, std::string>
  returnWithNewChallengeStatus(ca::RequestState& request, const std::string& challengeStatus,
                               JsonSection challengeSecret, size_t remainingTries, time::seconds remainingTime);

  std::tuple<ErrorCode, std::string>
  returnWithSuccess(ca::RequestState& request);

public:
  const std::string CHALLENGE_TYPE;

protected:
  const size_t m_maxAttemptTimes;
  const time::seconds m_secretLifetime;

private:
  using CreateFunc = std::function<std::unique_ptr<ChallengeModule>()>;
  using ChallengeFactory = std::map<std::string, CreateFunc>;

  static ChallengeFactory&
  getFactory();
};

} // namespace ndncert

#define NDNCERT_REGISTER_CHALLENGE(C, T)                            \
static class NdnCert##C##ChallengeRegistrationClass                 \
{                                                                   \
public:                                                             \
  NdnCert##C##ChallengeRegistrationClass()                          \
  {                                                                 \
    ::ndncert::ChallengeModule::registerChallengeModule<C>(T);      \
  }                                                                 \
} g_NdnCert##C##ChallengeRegistrationVariable

#endif // NDNCERT_CHALLENGE_MODULE_HPP
