// docker-finance | modern accounting for the power-user
//
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
//
// This program 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.
//
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.

//! \file
//! \author Aaron Fiore (Founder, Evergreen Crypto LLC)
//! \note File intended to be loaded into ROOT.cern framework / Cling interpreter
//! \since docker-finance 1.1.0

#ifndef CONTAINER_SRC_ROOT_COMMON_TYPE_HH_
#define CONTAINER_SRC_ROOT_COMMON_TYPE_HH_

#include <stdexcept>
#include <string>

//! \namespace dfi
//! \since docker-finance 1.0.0
namespace dfi
{
//! \namespace dfi::common
//! \brief Shared common functionality
//! \since docker-finance 1.1.0
namespace common
{
//! \namespace dfi::common::type
//! \brief docker-finance defined common types
//! \since docker-finance 1.1.0
namespace type
{
//! \brief Base exception class
//! \ingroup cpp_type_exceptions
class Exception : virtual public std::exception
{
 public:
  //! \brief Exception type tag
  enum struct kType : uint8_t
  {
    RuntimeError,
    InvalidArgument,
  };

  //! \brief Construct by type tag with given message
  Exception(const kType type, const std::string& what)
      : m_type(type), m_what(what)
  {
  }
  virtual ~Exception() = default;

  Exception(const Exception&) = default;
  Exception& operator=(const Exception&) = default;

  Exception(Exception&&) = default;
  Exception& operator=(Exception&&) = default;

 public:
  //! \return Exeption type tag
  kType type() const noexcept { return m_type; }

  //! \return Exception message
  const char* what() const noexcept { return m_what.c_str(); }

 private:
  kType m_type;
  std::string m_what;
};

//! \brief Exception type for runtime errors
//! \ingroup cpp_type_exceptions
struct RuntimeError final : public Exception
{
  explicit RuntimeError(const std::string& what = {})
      : Exception(Exception::kType::RuntimeError, what)
  {
  }
};

//! \brief Exception type for invalid arguments (logic error)
//! \ingroup cpp_type_exceptions
struct InvalidArgument final : public Exception
{
  explicit InvalidArgument(const std::string& what = {})
      : Exception(Exception::kType::InvalidArgument, what)
  {
  }
};
}  // namespace type
}  // namespace common
}  // namespace dfi

#endif  // CONTAINER_SRC_ROOT_COMMON_TYPE_HH_

// # vim: sw=2 sts=2 si ai et
