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

#include "geo_line_strings.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    GeoLineStrings GeoLineStrings::clear_fields() {
        auto archetype = GeoLineStrings();
        archetype.line_strings =
            ComponentBatch::empty<rerun::components::GeoLineString>(Descriptor_line_strings)
                .value_or_throw();
        archetype.radii =
            ComponentBatch::empty<rerun::components::Radius>(Descriptor_radii).value_or_throw();
        archetype.colors =
            ComponentBatch::empty<rerun::components::Color>(Descriptor_colors).value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> GeoLineStrings::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(3);
        if (line_strings.has_value()) {
            columns.push_back(line_strings.value().partitioned(lengths_).value_or_throw());
        }
        if (radii.has_value()) {
            columns.push_back(radii.value().partitioned(lengths_).value_or_throw());
        }
        if (colors.has_value()) {
            columns.push_back(colors.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> GeoLineStrings::columns() {
        if (line_strings.has_value()) {
            return columns(std::vector<uint32_t>(line_strings.value().length(), 1));
        }
        if (radii.has_value()) {
            return columns(std::vector<uint32_t>(radii.value().length(), 1));
        }
        if (colors.has_value()) {
            return columns(std::vector<uint32_t>(colors.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

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

        if (archetype.line_strings.has_value()) {
            cells.push_back(archetype.line_strings.value());
        }
        if (archetype.radii.has_value()) {
            cells.push_back(archetype.radii.value());
        }
        if (archetype.colors.has_value()) {
            cells.push_back(archetype.colors.value());
        }

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