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

#include "graph_edges.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    GraphEdges GraphEdges::clear_fields() {
        auto archetype = GraphEdges();
        archetype.edges =
            ComponentBatch::empty<rerun::components::GraphEdge>(Descriptor_edges).value_or_throw();
        archetype.graph_type =
            ComponentBatch::empty<rerun::components::GraphType>(Descriptor_graph_type)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> GraphEdges::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(3);
        if (edges.has_value()) {
            columns.push_back(edges.value().partitioned(lengths_).value_or_throw());
        }
        if (graph_type.has_value()) {
            columns.push_back(graph_type.value().partitioned(lengths_).value_or_throw());
        }
        columns.push_back(
            ComponentColumn::from_indicators<GraphEdges>(static_cast<uint32_t>(lengths_.size()))
                .value_or_throw()
        );
        return columns;
    }

    Collection<ComponentColumn> GraphEdges::columns() {
        if (edges.has_value()) {
            return columns(std::vector<uint32_t>(edges.value().length(), 1));
        }
        if (graph_type.has_value()) {
            return columns(std::vector<uint32_t>(graph_type.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

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

        if (archetype.edges.has_value()) {
            cells.push_back(archetype.edges.value());
        }
        if (archetype.graph_type.has_value()) {
            cells.push_back(archetype.graph_type.value());
        }
        {
            auto result = ComponentBatch::from_indicator<GraphEdges>();
            RR_RETURN_NOT_OK(result.error);
            cells.emplace_back(std::move(result.value));
        }

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