// 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/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(4);
        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());
        }
        columns.push_back(
            ComponentColumn::from_indicators<GeoLineStrings>(static_cast<uint32_t>(lengths_.size()))
                .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(4);

        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());
        }
        {
            auto result = ComponentBatch::from_indicator<GeoLineStrings>();
            RR_RETURN_NOT_OK(result.error);
            cells.emplace_back(std::move(result.value));
        }

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