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

#include "certificate-request.hpp"
#include "ndncert-common.hpp"

namespace ndn {
namespace ndncert {

class ChallengeModule : noncopyable {
public:
  explicit ChallengeModule(const std::string& uniqueType);

  virtual ~ChallengeModule();

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

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

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

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

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

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

  // helpers
  static std::string
  generateSecretCode();

protected:
  // used by challenge modules
  std::tuple<ErrorCode, std::string>
  returnWithError(CertificateRequest& request, ErrorCode errorCode, std::string&& errorInfo);

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

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

public:
  const std::string CHALLENGE_TYPE;

private:
  typedef function<unique_ptr<ChallengeModule>()> ChallengeCreateFunc;
  typedef std::map<std::string, ChallengeCreateFunc> ChallengeFactory;

  static ChallengeFactory&
  getFactory();
};

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

}  // namespace ndncert
}  // namespace ndn

#endif  // NDNCERT_CHALLENGE_MODULE_HPP
