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

#include "series_points.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    SeriesPoints SeriesPoints::clear_fields() {
        auto archetype = SeriesPoints();
        archetype.colors =
            ComponentBatch::empty<rerun::components::Color>(Descriptor_colors).value_or_throw();
        archetype.markers =
            ComponentBatch::empty<rerun::components::MarkerShape>(Descriptor_markers)
                .value_or_throw();
        archetype.names =
            ComponentBatch::empty<rerun::components::Name>(Descriptor_names).value_or_throw();
        archetype.visible_series =
            ComponentBatch::empty<rerun::components::SeriesVisible>(Descriptor_visible_series)
                .value_or_throw();
        archetype.marker_sizes =
            ComponentBatch::empty<rerun::components::MarkerSize>(Descriptor_marker_sizes)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> SeriesPoints::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(5);
        if (colors.has_value()) {
            columns.push_back(colors.value().partitioned(lengths_).value_or_throw());
        }
        if (markers.has_value()) {
            columns.push_back(markers.value().partitioned(lengths_).value_or_throw());
        }
        if (names.has_value()) {
            columns.push_back(names.value().partitioned(lengths_).value_or_throw());
        }
        if (visible_series.has_value()) {
            columns.push_back(visible_series.value().partitioned(lengths_).value_or_throw());
        }
        if (marker_sizes.has_value()) {
            columns.push_back(marker_sizes.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> SeriesPoints::columns() {
        if (colors.has_value()) {
            return columns(std::vector<uint32_t>(colors.value().length(), 1));
        }
        if (markers.has_value()) {
            return columns(std::vector<uint32_t>(markers.value().length(), 1));
        }
        if (names.has_value()) {
            return columns(std::vector<uint32_t>(names.value().length(), 1));
        }
        if (visible_series.has_value()) {
            return columns(std::vector<uint32_t>(visible_series.value().length(), 1));
        }
        if (marker_sizes.has_value()) {
            return columns(std::vector<uint32_t>(marker_sizes.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

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

        if (archetype.colors.has_value()) {
            cells.push_back(archetype.colors.value());
        }
        if (archetype.markers.has_value()) {
            cells.push_back(archetype.markers.value());
        }
        if (archetype.names.has_value()) {
            cells.push_back(archetype.names.value());
        }
        if (archetype.visible_series.has_value()) {
            cells.push_back(archetype.visible_series.value());
        }
        if (archetype.marker_sizes.has_value()) {
            cells.push_back(archetype.marker_sizes.value());
        }

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