// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
// Based on "crates/store/re_sdk_types/definitions/rerun/blueprint/archetypes/background.fbs".

#include "plot_background.hpp"

#include "../../collection_adapter_builtins.hpp"

namespace rerun::blueprint::archetypes {
    PlotBackground PlotBackground::clear_fields() {
        auto archetype = PlotBackground();
        archetype.color =
            ComponentBatch::empty<rerun::components::Color>(Descriptor_color).value_or_throw();
        archetype.show_grid =
            ComponentBatch::empty<rerun::blueprint::components::Enabled>(Descriptor_show_grid)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> PlotBackground::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(2);
        if (color.has_value()) {
            columns.push_back(color.value().partitioned(lengths_).value_or_throw());
        }
        if (show_grid.has_value()) {
            columns.push_back(show_grid.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> PlotBackground::columns() {
        if (color.has_value()) {
            return columns(std::vector<uint32_t>(color.value().length(), 1));
        }
        if (show_grid.has_value()) {
            return columns(std::vector<uint32_t>(show_grid.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::blueprint::archetypes

namespace rerun {

    Result<Collection<ComponentBatch>>
        AsComponents<blueprint::archetypes::PlotBackground>::as_batches(
            const blueprint::archetypes::PlotBackground& archetype
        ) {
        using namespace blueprint::archetypes;
        std::vector<ComponentBatch> cells;
        cells.reserve(2);

        if (archetype.color.has_value()) {
            cells.push_back(archetype.color.value());
        }
        if (archetype.show_grid.has_value()) {
            cells.push_back(archetype.show_grid.value());
        }

        return rerun::take_ownership(std::move(cells));
    }
} // namespace rerun
