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

#include "text_log.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    TextLog TextLog::clear_fields() {
        auto archetype = TextLog();
        archetype.text =
            ComponentBatch::empty<rerun::components::Text>(Descriptor_text).value_or_throw();
        archetype.level = ComponentBatch::empty<rerun::components::TextLogLevel>(Descriptor_level)
                              .value_or_throw();
        archetype.color =
            ComponentBatch::empty<rerun::components::Color>(Descriptor_color).value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> TextLog::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(3);
        if (text.has_value()) {
            columns.push_back(text.value().partitioned(lengths_).value_or_throw());
        }
        if (level.has_value()) {
            columns.push_back(level.value().partitioned(lengths_).value_or_throw());
        }
        if (color.has_value()) {
            columns.push_back(color.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> TextLog::columns() {
        if (text.has_value()) {
            return columns(std::vector<uint32_t>(text.value().length(), 1));
        }
        if (level.has_value()) {
            return columns(std::vector<uint32_t>(level.value().length(), 1));
        }
        if (color.has_value()) {
            return columns(std::vector<uint32_t>(color.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

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

        if (archetype.text.has_value()) {
            cells.push_back(archetype.text.value());
        }
        if (archetype.level.has_value()) {
            cells.push_back(archetype.level.value());
        }
        if (archetype.color.has_value()) {
            cells.push_back(archetype.color.value());
        }

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