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

#include "scalar_axis.hpp"

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

namespace rerun::blueprint::archetypes {
    ScalarAxis ScalarAxis::clear_fields() {
        auto archetype = ScalarAxis();
        archetype.range =
            ComponentBatch::empty<rerun::components::Range1D>(Descriptor_range).value_or_throw();
        archetype.zoom_lock =
            ComponentBatch::empty<rerun::blueprint::components::LockRangeDuringZoom>(
                Descriptor_zoom_lock
            )
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> ScalarAxis::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(2);
        if (range.has_value()) {
            columns.push_back(range.value().partitioned(lengths_).value_or_throw());
        }
        if (zoom_lock.has_value()) {
            columns.push_back(zoom_lock.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> ScalarAxis::columns() {
        if (range.has_value()) {
            return columns(std::vector<uint32_t>(range.value().length(), 1));
        }
        if (zoom_lock.has_value()) {
            return columns(std::vector<uint32_t>(zoom_lock.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::blueprint::archetypes

namespace rerun {

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

        if (archetype.range.has_value()) {
            cells.push_back(archetype.range.value());
        }
        if (archetype.zoom_lock.has_value()) {
            cells.push_back(archetype.zoom_lock.value());
        }

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