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

#include "force_link.hpp"

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

namespace rerun::blueprint::archetypes {
    ForceLink ForceLink::clear_fields() {
        auto archetype = ForceLink();
        archetype.enabled =
            ComponentBatch::empty<rerun::blueprint::components::Enabled>(Descriptor_enabled)
                .value_or_throw();
        archetype.distance =
            ComponentBatch::empty<rerun::blueprint::components::ForceDistance>(Descriptor_distance)
                .value_or_throw();
        archetype.iterations = ComponentBatch::empty<rerun::blueprint::components::ForceIterations>(
                                   Descriptor_iterations
        )
                                   .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> ForceLink::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(3);
        if (enabled.has_value()) {
            columns.push_back(enabled.value().partitioned(lengths_).value_or_throw());
        }
        if (distance.has_value()) {
            columns.push_back(distance.value().partitioned(lengths_).value_or_throw());
        }
        if (iterations.has_value()) {
            columns.push_back(iterations.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> ForceLink::columns() {
        if (enabled.has_value()) {
            return columns(std::vector<uint32_t>(enabled.value().length(), 1));
        }
        if (distance.has_value()) {
            return columns(std::vector<uint32_t>(distance.value().length(), 1));
        }
        if (iterations.has_value()) {
            return columns(std::vector<uint32_t>(iterations.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::blueprint::archetypes

namespace rerun {

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

        if (archetype.enabled.has_value()) {
            cells.push_back(archetype.enabled.value());
        }
        if (archetype.distance.has_value()) {
            cells.push_back(archetype.distance.value());
        }
        if (archetype.iterations.has_value()) {
            cells.push_back(archetype.iterations.value());
        }

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