#include "pch.h"
#include "app.h"
#include "app_core/document_cloud.h"
#include "legacy_cloud_services.h"
#include "util.h"

void App::cloud_upload()
{
    const bool has_canvas = canvas != nullptr;
    const auto plan = pp::app::plan_cloud_upload(
        has_canvas,
        has_canvas && Canvas::I->m_newdoc,
        has_canvas && Canvas::I->m_unsaved);

    const auto status = pp::panopainter::execute_legacy_cloud_upload_plan(*this, plan);
    if (!status.ok())
        LOG("Cloud upload action failed: %s", status.message);
}

void App::cloud_upload_all()
{
    pp::panopainter::queue_legacy_cloud_worker_task([this] {
        BT_SetTerminate();

        auto names = Asset::list_files(data_path, ".*\\.ppi");
        const auto plan = pp::app::plan_cloud_bulk_upload(names.size(), layout.m_loaded);

        const auto status = pp::panopainter::execute_legacy_cloud_bulk_upload_plan(*this, plan);
        if (!status.ok())
            LOG("Cloud bulk upload action failed: %s", status.message);
    });
}

void App::cloud_browse()
{
    const auto browse_plan = pp::app::plan_cloud_browse(canvas != nullptr);
    const auto status = pp::panopainter::execute_legacy_cloud_browse_action(*this, browse_plan);
    if (!status.ok())
        LOG("Cloud browse action failed: %s", status.message);
}
