/*
  Copyright <2018-2025> <scott.e.graves@protonmail.com>

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
*/
#ifndef REPERTORY_INCLUDE_EVENTS_TYPES_ORPHANED_FILE_PROCESSING_FAILED_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_ORPHANED_FILE_PROCESSING_FAILED_HPP_

#include "events/i_event.hpp"
#include "types/repertory.hpp"

namespace repertory {
struct orphaned_file_processing_failed final : public i_event {
  orphaned_file_processing_failed() = default;
  orphaned_file_processing_failed(std::string dest_path_, std::string error_,
                                  std::string_view function_name_,
                                  std::string source_path_)
      : dest_path(std::move(dest_path_)),
        error(std::move(error_)),
        function_name(std::string(function_name_)),
        source_path(std::move(source_path_)) {}

  static constexpr const event_level level{event_level::error};
  static constexpr const std::string_view name{
      "orphaned_file_processing_failed",
  };

  std::string dest_path;
  std::string error;
  std::string function_name;
  std::string source_path;

  [[nodiscard]] auto get_event_level() const -> event_level override {
    return level;
  }

  [[nodiscard]] auto get_name() const -> std::string_view override {
    return name;
  }

  [[nodiscard]] auto get_single_line() const -> std::string override {
    return fmt::format("{}|func|{}|sp|{}|dp|{}|error|{}", name, function_name,
                       source_path, dest_path, error);
  }
};
} // namespace repertory

NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::orphaned_file_processing_failed> {
  static void to_json(json &data,
                      const repertory::orphaned_file_processing_failed &value) {
    data["dest_path"] = value.dest_path;
    data["error"] = value.error;
    data["function_name"] = value.function_name;
    data["source_path"] = value.source_path;
  }

  static void from_json(const json &data,
                        repertory::orphaned_file_processing_failed &value) {
    data.at("dest_path").get_to<std::string>(value.dest_path);
    data.at("error").get_to<std::string>(value.error);
    data.at("function_name").get_to<std::string>(value.function_name);
    data.at("source_path").get_to<std::string>(value.source_path);
  }
};
NLOHMANN_JSON_NAMESPACE_END

#endif // REPERTORY_INCLUDE_EVENTS_TYPES_ORPHANED_FILE_PROCESSING_FAILED_HPP_
