#pragma once

#include <string>
#include <memory>
#include <vector>
#include <map>

#include "security_db_record.hh"

class OCTETSTRING;

/*!
 * \class security_db
 * \brief This class provides security record description for security database
 */
class security_db {
  std::map<const std::string, std::unique_ptr<security_db_record> > _certificates; //! List of the certificates indexed by the certficate identifier
  std::map<const std::vector<unsigned char>, const std::string&> _hashed_id8s; //! List of the certificates indexed by the HashedId8
  
public: /*! \publicsection */
  /*!
   * \brief Default ctor
   */
  security_db();
  /*!
   * \brief Ctor with full path to the certificates storage
   */
  security_db(const std::string& p_db_path);
  /*!
   * \brief Default private dtor
   */
  ~security_db();

  int get_certificate_id(const OCTETSTRING& p_hashed_id8, std::string& p_certifcate_id) const;
  int get_certificate(const std::string& p_certifcate_id, OCTETSTRING& p_certificate) const;
  int get_hashed_id_issuer(const std::string& p_certifcate_id, OCTETSTRING& p_hashed_id_issuer) const;
  int get_hashed_id(const std::string& p_certifcate_id, OCTETSTRING& p_hashed_id) const;
  int get_private_key(const std::string& p_certifcate_id, OCTETSTRING& p_private_key) const;
  int get_public_keys(const std::string& p_certifcate_id, OCTETSTRING& p_public_key_x, OCTETSTRING& p_public_key_y) const;
  void dump() const;

private:
  int load_from_files(const std::string& p_db_path);
  int simulate_certificates();
}; // End of class security_db
