#pragma once

#include "app_core/app_dialog.h"
#include "foundation/result.h"

#include <string>
#include <string_view>

namespace pp::app {

struct BrushPackageExportRequest {
    std::string author;
    std::string email;
    std::string url;
    std::string description;
    std::string destination_path;
    bool export_data = false;
    bool has_header_image = false;
};

class BrushPackageExportServices {
public:
    virtual ~BrushPackageExportServices() = default;

    virtual void export_brush_package(std::string_view path, const BrushPackageExportRequest& request) = 0;
};

[[nodiscard]] inline pp::foundation::Status validate_brush_package_export_path(std::string_view path) noexcept
{
    if (path.empty()) {
        return pp::foundation::Status::invalid_argument("brush package export path must not be empty");
    }

    return pp::foundation::Status::success();
}

[[nodiscard]] inline AppMessageDialogPlan plan_brush_package_export_success_dialog(std::string_view path)
{
    std::string message = "Brushes exported to:\n";
    message += path;
    return plan_app_message_dialog("Export PPBR", message, false);
}

[[nodiscard]] inline pp::foundation::Status validate_brush_package_export_request(
    std::string_view path,
    const BrushPackageExportRequest& request) noexcept
{
    (void)request;
    const auto path_status = validate_brush_package_export_path(path);
    if (!path_status.ok()) {
        return path_status;
    }

    return pp::foundation::Status::success();
}

[[nodiscard]] inline pp::foundation::Status execute_brush_package_export(
    std::string_view path,
    const BrushPackageExportRequest& request,
    BrushPackageExportServices& services)
{
    const auto status = validate_brush_package_export_request(path, request);
    if (!status.ok()) {
        return status;
    }

    services.export_brush_package(path, request);
    return pp::foundation::Status::success();
}

} // namespace pp::app
