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

#include "series_lines.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    SeriesLines SeriesLines::clear_fields() {
        auto archetype = SeriesLines();
        archetype.colors =
            ComponentBatch::empty<rerun::components::Color>(Descriptor_colors).value_or_throw();
        archetype.widths = ComponentBatch::empty<rerun::components::StrokeWidth>(Descriptor_widths)
                               .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.aggregation_policy = ComponentBatch::empty<rerun::components::AggregationPolicy>(
                                           Descriptor_aggregation_policy
        )
                                           .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> SeriesLines::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 (widths.has_value()) {
            columns.push_back(widths.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 (aggregation_policy.has_value()) {
            columns.push_back(aggregation_policy.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> SeriesLines::columns() {
        if (colors.has_value()) {
            return columns(std::vector<uint32_t>(colors.value().length(), 1));
        }
        if (widths.has_value()) {
            return columns(std::vector<uint32_t>(widths.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 (aggregation_policy.has_value()) {
            return columns(std::vector<uint32_t>(aggregation_policy.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

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

        if (archetype.colors.has_value()) {
            cells.push_back(archetype.colors.value());
        }
        if (archetype.widths.has_value()) {
            cells.push_back(archetype.widths.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.aggregation_policy.has_value()) {
            cells.push_back(archetype.aggregation_policy.value());
        }

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