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

#include "graph_nodes.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    GraphNodes GraphNodes::clear_fields() {
        auto archetype = GraphNodes();
        archetype.node_ids =
            ComponentBatch::empty<rerun::components::GraphNode>(Descriptor_node_ids)
                .value_or_throw();
        archetype.positions =
            ComponentBatch::empty<rerun::components::Position2D>(Descriptor_positions)
                .value_or_throw();
        archetype.colors =
            ComponentBatch::empty<rerun::components::Color>(Descriptor_colors).value_or_throw();
        archetype.labels =
            ComponentBatch::empty<rerun::components::Text>(Descriptor_labels).value_or_throw();
        archetype.show_labels =
            ComponentBatch::empty<rerun::components::ShowLabels>(Descriptor_show_labels)
                .value_or_throw();
        archetype.radii =
            ComponentBatch::empty<rerun::components::Radius>(Descriptor_radii).value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> GraphNodes::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(6);
        if (node_ids.has_value()) {
            columns.push_back(node_ids.value().partitioned(lengths_).value_or_throw());
        }
        if (positions.has_value()) {
            columns.push_back(positions.value().partitioned(lengths_).value_or_throw());
        }
        if (colors.has_value()) {
            columns.push_back(colors.value().partitioned(lengths_).value_or_throw());
        }
        if (labels.has_value()) {
            columns.push_back(labels.value().partitioned(lengths_).value_or_throw());
        }
        if (show_labels.has_value()) {
            columns.push_back(show_labels.value().partitioned(lengths_).value_or_throw());
        }
        if (radii.has_value()) {
            columns.push_back(radii.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> GraphNodes::columns() {
        if (node_ids.has_value()) {
            return columns(std::vector<uint32_t>(node_ids.value().length(), 1));
        }
        if (positions.has_value()) {
            return columns(std::vector<uint32_t>(positions.value().length(), 1));
        }
        if (colors.has_value()) {
            return columns(std::vector<uint32_t>(colors.value().length(), 1));
        }
        if (labels.has_value()) {
            return columns(std::vector<uint32_t>(labels.value().length(), 1));
        }
        if (show_labels.has_value()) {
            return columns(std::vector<uint32_t>(show_labels.value().length(), 1));
        }
        if (radii.has_value()) {
            return columns(std::vector<uint32_t>(radii.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

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

        if (archetype.node_ids.has_value()) {
            cells.push_back(archetype.node_ids.value());
        }
        if (archetype.positions.has_value()) {
            cells.push_back(archetype.positions.value());
        }
        if (archetype.colors.has_value()) {
            cells.push_back(archetype.colors.value());
        }
        if (archetype.labels.has_value()) {
            cells.push_back(archetype.labels.value());
        }
        if (archetype.show_labels.has_value()) {
            cells.push_back(archetype.show_labels.value());
        }
        if (archetype.radii.has_value()) {
            cells.push_back(archetype.radii.value());
        }

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