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

#include "eye_controls3d.hpp"

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

namespace rerun::blueprint::archetypes {
    EyeControls3D EyeControls3D::clear_fields() {
        auto archetype = EyeControls3D();
        archetype.kind =
            ComponentBatch::empty<rerun::blueprint::components::Eye3DKind>(Descriptor_kind)
                .value_or_throw();
        archetype.position =
            ComponentBatch::empty<rerun::components::Position3D>(Descriptor_position)
                .value_or_throw();
        archetype.look_target =
            ComponentBatch::empty<rerun::components::Position3D>(Descriptor_look_target)
                .value_or_throw();
        archetype.eye_up =
            ComponentBatch::empty<rerun::components::Vector3D>(Descriptor_eye_up).value_or_throw();
        archetype.speed = ComponentBatch::empty<rerun::components::LinearSpeed>(Descriptor_speed)
                              .value_or_throw();
        archetype.tracking_entity =
            ComponentBatch::empty<rerun::components::EntityPath>(Descriptor_tracking_entity)
                .value_or_throw();
        archetype.spin_speed =
            ComponentBatch::empty<rerun::blueprint::components::AngularSpeed>(Descriptor_spin_speed)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> EyeControls3D::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(7);
        if (kind.has_value()) {
            columns.push_back(kind.value().partitioned(lengths_).value_or_throw());
        }
        if (position.has_value()) {
            columns.push_back(position.value().partitioned(lengths_).value_or_throw());
        }
        if (look_target.has_value()) {
            columns.push_back(look_target.value().partitioned(lengths_).value_or_throw());
        }
        if (eye_up.has_value()) {
            columns.push_back(eye_up.value().partitioned(lengths_).value_or_throw());
        }
        if (speed.has_value()) {
            columns.push_back(speed.value().partitioned(lengths_).value_or_throw());
        }
        if (tracking_entity.has_value()) {
            columns.push_back(tracking_entity.value().partitioned(lengths_).value_or_throw());
        }
        if (spin_speed.has_value()) {
            columns.push_back(spin_speed.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> EyeControls3D::columns() {
        if (kind.has_value()) {
            return columns(std::vector<uint32_t>(kind.value().length(), 1));
        }
        if (position.has_value()) {
            return columns(std::vector<uint32_t>(position.value().length(), 1));
        }
        if (look_target.has_value()) {
            return columns(std::vector<uint32_t>(look_target.value().length(), 1));
        }
        if (eye_up.has_value()) {
            return columns(std::vector<uint32_t>(eye_up.value().length(), 1));
        }
        if (speed.has_value()) {
            return columns(std::vector<uint32_t>(speed.value().length(), 1));
        }
        if (tracking_entity.has_value()) {
            return columns(std::vector<uint32_t>(tracking_entity.value().length(), 1));
        }
        if (spin_speed.has_value()) {
            return columns(std::vector<uint32_t>(spin_speed.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::blueprint::archetypes

namespace rerun {

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

        if (archetype.kind.has_value()) {
            cells.push_back(archetype.kind.value());
        }
        if (archetype.position.has_value()) {
            cells.push_back(archetype.position.value());
        }
        if (archetype.look_target.has_value()) {
            cells.push_back(archetype.look_target.value());
        }
        if (archetype.eye_up.has_value()) {
            cells.push_back(archetype.eye_up.value());
        }
        if (archetype.speed.has_value()) {
            cells.push_back(archetype.speed.value());
        }
        if (archetype.tracking_entity.has_value()) {
            cells.push_back(archetype.tracking_entity.value());
        }
        if (archetype.spin_speed.has_value()) {
            cells.push_back(archetype.spin_speed.value());
        }

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