//          Copyright Carl Philipp Reh 2009 - 2021.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#include <fcppt/options/error.hpp>
#include <fcppt/options/error_product.hpp>
#include <fcppt/options/error_sum.hpp>
#include <fcppt/options/error_variant.hpp>
#include <fcppt/options/missing_argument_error.hpp>
#include <fcppt/options/missing_command_error.hpp>
#include <fcppt/options/missing_error_product.hpp>
#include <fcppt/options/missing_error_sum.hpp>
#include <fcppt/options/missing_error_variant.hpp>
#include <fcppt/options/missing_flag_error.hpp>
#include <fcppt/options/missing_option_error.hpp>
#include <fcppt/options/detail/missing_error_to_error.hpp>
#include <fcppt/variant/match.hpp>
#include <fcppt/config/external_begin.hpp>
#include <utility>
#include <fcppt/config/external_end.hpp>

fcppt::options::error
fcppt::options::detail::missing_error_to_error(fcppt::options::missing_error_variant &&_error)
{
  return fcppt::variant::match(
      std::move(_error),
      [](fcppt::options::missing_argument_error &&_inner)
      { return fcppt::options::error{fcppt::options::error_variant{std::move(_inner)}}; },
      [](fcppt::options::missing_command_error &&_inner)
      { return fcppt::options::error{fcppt::options::error_variant{std::move(_inner)}}; },
      // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
      [](fcppt::options::missing_error_product &&_inner)
      {
        return fcppt::options::error{fcppt::options::error_variant{fcppt::options::error_product{
            fcppt::options::detail::missing_error_to_error(std::move(_inner.left())),
            fcppt::options::detail::missing_error_to_error(std::move(_inner.right()))}}};
      },
      // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
      [](fcppt::options::missing_error_sum &&_inner)
      {
        return fcppt::options::error{fcppt::options::error_variant{fcppt::options::error_sum{
            fcppt::options::detail::missing_error_to_error(std::move(_inner.left())),
            fcppt::options::detail::missing_error_to_error(std::move(_inner.right()))}}};
      },
      [](fcppt::options::missing_flag_error &&_inner)
      { return fcppt::options::error{fcppt::options::error_variant{std::move(_inner)}}; },
      [](fcppt::options::missing_option_error &&_inner)
      { return fcppt::options::error{fcppt::options::error_variant{std::move(_inner)}}; });
}
