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

#include "asset_video.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    AssetVideo AssetVideo::clear_fields() {
        auto archetype = AssetVideo();
        archetype.blob =
            ComponentBatch::empty<rerun::components::Blob>(Descriptor_blob).value_or_throw();
        archetype.media_type =
            ComponentBatch::empty<rerun::components::MediaType>(Descriptor_media_type)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> AssetVideo::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(3);
        if (blob.has_value()) {
            columns.push_back(blob.value().partitioned(lengths_).value_or_throw());
        }
        if (media_type.has_value()) {
            columns.push_back(media_type.value().partitioned(lengths_).value_or_throw());
        }
        columns.push_back(
            ComponentColumn::from_indicators<AssetVideo>(static_cast<uint32_t>(lengths_.size()))
                .value_or_throw()
        );
        return columns;
    }

    Collection<ComponentColumn> AssetVideo::columns() {
        if (blob.has_value()) {
            return columns(std::vector<uint32_t>(blob.value().length(), 1));
        }
        if (media_type.has_value()) {
            return columns(std::vector<uint32_t>(media_type.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

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

        if (archetype.blob.has_value()) {
            cells.push_back(archetype.blob.value());
        }
        if (archetype.media_type.has_value()) {
            cells.push_back(archetype.media_type.value());
        }
        {
            auto result = ComponentBatch::from_indicator<AssetVideo>();
            RR_RETURN_NOT_OK(result.error);
            cells.emplace_back(std::move(result.value));
        }

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