// 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/spatial_information.fbs".

#include "spatial_information.hpp"

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

namespace rerun::blueprint::archetypes {
    SpatialInformation SpatialInformation::clear_fields() {
        auto archetype = SpatialInformation();
        archetype.target_frame =
            ComponentBatch::empty<rerun::components::TransformFrameId>(Descriptor_target_frame)
                .value_or_throw();
        archetype.show_axes =
            ComponentBatch::empty<rerun::blueprint::components::Enabled>(Descriptor_show_axes)
                .value_or_throw();
        archetype.show_bounding_box = ComponentBatch::empty<rerun::blueprint::components::Enabled>(
                                          Descriptor_show_bounding_box
        )
                                          .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> SpatialInformation::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(3);
        if (target_frame.has_value()) {
            columns.push_back(target_frame.value().partitioned(lengths_).value_or_throw());
        }
        if (show_axes.has_value()) {
            columns.push_back(show_axes.value().partitioned(lengths_).value_or_throw());
        }
        if (show_bounding_box.has_value()) {
            columns.push_back(show_bounding_box.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> SpatialInformation::columns() {
        if (target_frame.has_value()) {
            return columns(std::vector<uint32_t>(target_frame.value().length(), 1));
        }
        if (show_axes.has_value()) {
            return columns(std::vector<uint32_t>(show_axes.value().length(), 1));
        }
        if (show_bounding_box.has_value()) {
            return columns(std::vector<uint32_t>(show_bounding_box.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::blueprint::archetypes

namespace rerun {

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

        if (archetype.target_frame.has_value()) {
            cells.push_back(archetype.target_frame.value());
        }
        if (archetype.show_axes.has_value()) {
            cells.push_back(archetype.show_axes.value());
        }
        if (archetype.show_bounding_box.has_value()) {
            cells.push_back(archetype.show_bounding_box.value());
        }

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