#pragma once

#include <cstddef>
#include <limits>
#include <string_view>

namespace pp::app {

enum class CloudUploadAction {
    unavailable_no_canvas,
    show_save_required_warning,
    prompt_publish,
};

enum class CloudBrowseAction {
    unavailable_no_canvas,
    show_browser,
};

enum class CloudDownloadSelectionAction {
    wait_for_selection,
    start_download,
};

struct CloudUploadPlan {
    CloudUploadAction action = CloudUploadAction::unavailable_no_canvas;
    bool save_before_upload = false;
};

struct CloudBulkUploadPlan {
    std::size_t file_count = 0;
    int progress_total = 0;
    bool show_progress = false;
};

[[nodiscard]] constexpr CloudUploadPlan plan_cloud_upload(
    bool has_canvas,
    bool is_new_document,
    bool has_unsaved_changes) noexcept
{
    if (!has_canvas) {
        return { CloudUploadAction::unavailable_no_canvas, false };
    }

    if (is_new_document) {
        return { CloudUploadAction::show_save_required_warning, false };
    }

    return { CloudUploadAction::prompt_publish, has_unsaved_changes };
}

[[nodiscard]] constexpr CloudBrowseAction plan_cloud_browse(bool has_canvas) noexcept
{
    return has_canvas
        ? CloudBrowseAction::show_browser
        : CloudBrowseAction::unavailable_no_canvas;
}

[[nodiscard]] constexpr CloudDownloadSelectionAction plan_cloud_download_selection(
    std::string_view selected_file) noexcept
{
    return selected_file.empty()
        ? CloudDownloadSelectionAction::wait_for_selection
        : CloudDownloadSelectionAction::start_download;
}

[[nodiscard]] constexpr CloudBulkUploadPlan plan_cloud_bulk_upload(
    std::size_t file_count,
    bool progress_ui_available) noexcept
{
    const auto max_progress_total = static_cast<std::size_t>(std::numeric_limits<int>::max());
    return {
        file_count,
        file_count > max_progress_total ? std::numeric_limits<int>::max() : static_cast<int>(file_count),
        progress_ui_available,
    };
}

}
