#pragma once

#include "paint_renderer/compositor.h"
#include "renderer_api/renderer_api.h"

#include <algorithm>
#include <cstdint>

namespace pp::panopainter {

[[nodiscard]] inline pp::paint_renderer::CanvasStrokeRasterizationPlan plan_legacy_canvas_stroke_rasterization(
    pp::renderer::RenderDeviceFeatures features,
    int width,
    int height) noexcept
{
    const auto plan = pp::paint_renderer::plan_canvas_stroke_rasterization(
        features,
        pp::renderer::Extent2D {
            .width = static_cast<std::uint32_t>(std::max(width, 0)),
            .height = static_cast<std::uint32_t>(std::max(height, 0)),
        });
    if (plan) {
        return plan.value();
    }

    pp::paint_renderer::CanvasStrokeRasterizationPlan fallback;
    fallback.feedback.compatibility_fallback = true;
    fallback.feedback.path = pp::paint_renderer::StrokeCompositePath::ping_pong_textures;
    fallback.feedback.requires_auxiliary_texture = true;
    fallback.copy_stroke_destination = true;
    fallback.compatibility_fallback = true;
    return fallback;
}

[[nodiscard]] inline pp::paint_renderer::CanvasStrokeMaterialPlan plan_legacy_canvas_stroke_material(
    pp::paint_renderer::CanvasStrokeMaterialRequest request) noexcept
{
    return pp::paint_renderer::plan_canvas_stroke_material(request);
}

} // namespace pp::panopainter
