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

#include "video_stream.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    VideoStream VideoStream::clear_fields() {
        auto archetype = VideoStream();
        archetype.codec =
            ComponentBatch::empty<rerun::components::VideoCodec>(Descriptor_codec).value_or_throw();
        archetype.sample = ComponentBatch::empty<rerun::components::VideoSample>(Descriptor_sample)
                               .value_or_throw();
        archetype.opacity =
            ComponentBatch::empty<rerun::components::Opacity>(Descriptor_opacity).value_or_throw();
        archetype.draw_order =
            ComponentBatch::empty<rerun::components::DrawOrder>(Descriptor_draw_order)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> VideoStream::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(4);
        if (codec.has_value()) {
            columns.push_back(codec.value().partitioned(lengths_).value_or_throw());
        }
        if (sample.has_value()) {
            columns.push_back(sample.value().partitioned(lengths_).value_or_throw());
        }
        if (opacity.has_value()) {
            columns.push_back(opacity.value().partitioned(lengths_).value_or_throw());
        }
        if (draw_order.has_value()) {
            columns.push_back(draw_order.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> VideoStream::columns() {
        if (codec.has_value()) {
            return columns(std::vector<uint32_t>(codec.value().length(), 1));
        }
        if (sample.has_value()) {
            return columns(std::vector<uint32_t>(sample.value().length(), 1));
        }
        if (opacity.has_value()) {
            return columns(std::vector<uint32_t>(opacity.value().length(), 1));
        }
        if (draw_order.has_value()) {
            return columns(std::vector<uint32_t>(draw_order.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

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

        if (archetype.codec.has_value()) {
            cells.push_back(archetype.codec.value());
        }
        if (archetype.sample.has_value()) {
            cells.push_back(archetype.sample.value());
        }
        if (archetype.opacity.has_value()) {
            cells.push_back(archetype.opacity.value());
        }
        if (archetype.draw_order.has_value()) {
            cells.push_back(archetype.draw_order.value());
        }

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