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

#include "mcap_schema.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    McapSchema McapSchema::clear_fields() {
        auto archetype = McapSchema();
        archetype.id =
            ComponentBatch::empty<rerun::components::SchemaId>(Descriptor_id).value_or_throw();
        archetype.name =
            ComponentBatch::empty<rerun::components::Text>(Descriptor_name).value_or_throw();
        archetype.encoding =
            ComponentBatch::empty<rerun::components::Text>(Descriptor_encoding).value_or_throw();
        archetype.data =
            ComponentBatch::empty<rerun::components::Blob>(Descriptor_data).value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> McapSchema::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(4);
        if (id.has_value()) {
            columns.push_back(id.value().partitioned(lengths_).value_or_throw());
        }
        if (name.has_value()) {
            columns.push_back(name.value().partitioned(lengths_).value_or_throw());
        }
        if (encoding.has_value()) {
            columns.push_back(encoding.value().partitioned(lengths_).value_or_throw());
        }
        if (data.has_value()) {
            columns.push_back(data.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> McapSchema::columns() {
        if (id.has_value()) {
            return columns(std::vector<uint32_t>(id.value().length(), 1));
        }
        if (name.has_value()) {
            return columns(std::vector<uint32_t>(name.value().length(), 1));
        }
        if (encoding.has_value()) {
            return columns(std::vector<uint32_t>(encoding.value().length(), 1));
        }
        if (data.has_value()) {
            return columns(std::vector<uint32_t>(data.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

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

        if (archetype.id.has_value()) {
            cells.push_back(archetype.id.value());
        }
        if (archetype.name.has_value()) {
            cells.push_back(archetype.name.value());
        }
        if (archetype.encoding.has_value()) {
            cells.push_back(archetype.encoding.value());
        }
        if (archetype.data.has_value()) {
            cells.push_back(archetype.data.value());
        }

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