// 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/blueprint/archetypes/panel_blueprint.fbs".

#include "time_panel_blueprint.hpp"

#include "../../collection_adapter_builtins.hpp"

namespace rerun::blueprint::archetypes {
    TimePanelBlueprint TimePanelBlueprint::clear_fields() {
        auto archetype = TimePanelBlueprint();
        archetype.state =
            ComponentBatch::empty<rerun::blueprint::components::PanelState>(Descriptor_state)
                .value_or_throw();
        archetype.timeline =
            ComponentBatch::empty<rerun::blueprint::components::TimelineName>(Descriptor_timeline)
                .value_or_throw();
        archetype.playback_speed =
            ComponentBatch::empty<rerun::blueprint::components::PlaybackSpeed>(
                Descriptor_playback_speed
            )
                .value_or_throw();
        archetype.fps = ComponentBatch::empty<rerun::blueprint::components::Fps>(Descriptor_fps)
                            .value_or_throw();
        archetype.play_state =
            ComponentBatch::empty<rerun::blueprint::components::PlayState>(Descriptor_play_state)
                .value_or_throw();
        archetype.loop_mode =
            ComponentBatch::empty<rerun::blueprint::components::LoopMode>(Descriptor_loop_mode)
                .value_or_throw();
        archetype.time_selection =
            ComponentBatch::empty<rerun::blueprint::components::AbsoluteTimeRange>(
                Descriptor_time_selection
            )
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> TimePanelBlueprint::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(7);
        if (state.has_value()) {
            columns.push_back(state.value().partitioned(lengths_).value_or_throw());
        }
        if (timeline.has_value()) {
            columns.push_back(timeline.value().partitioned(lengths_).value_or_throw());
        }
        if (playback_speed.has_value()) {
            columns.push_back(playback_speed.value().partitioned(lengths_).value_or_throw());
        }
        if (fps.has_value()) {
            columns.push_back(fps.value().partitioned(lengths_).value_or_throw());
        }
        if (play_state.has_value()) {
            columns.push_back(play_state.value().partitioned(lengths_).value_or_throw());
        }
        if (loop_mode.has_value()) {
            columns.push_back(loop_mode.value().partitioned(lengths_).value_or_throw());
        }
        if (time_selection.has_value()) {
            columns.push_back(time_selection.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> TimePanelBlueprint::columns() {
        if (state.has_value()) {
            return columns(std::vector<uint32_t>(state.value().length(), 1));
        }
        if (timeline.has_value()) {
            return columns(std::vector<uint32_t>(timeline.value().length(), 1));
        }
        if (playback_speed.has_value()) {
            return columns(std::vector<uint32_t>(playback_speed.value().length(), 1));
        }
        if (fps.has_value()) {
            return columns(std::vector<uint32_t>(fps.value().length(), 1));
        }
        if (play_state.has_value()) {
            return columns(std::vector<uint32_t>(play_state.value().length(), 1));
        }
        if (loop_mode.has_value()) {
            return columns(std::vector<uint32_t>(loop_mode.value().length(), 1));
        }
        if (time_selection.has_value()) {
            return columns(std::vector<uint32_t>(time_selection.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::blueprint::archetypes

namespace rerun {

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

        if (archetype.state.has_value()) {
            cells.push_back(archetype.state.value());
        }
        if (archetype.timeline.has_value()) {
            cells.push_back(archetype.timeline.value());
        }
        if (archetype.playback_speed.has_value()) {
            cells.push_back(archetype.playback_speed.value());
        }
        if (archetype.fps.has_value()) {
            cells.push_back(archetype.fps.value());
        }
        if (archetype.play_state.has_value()) {
            cells.push_back(archetype.play_state.value());
        }
        if (archetype.loop_mode.has_value()) {
            cells.push_back(archetype.loop_mode.value());
        }
        if (archetype.time_selection.has_value()) {
            cells.push_back(archetype.time_selection.value());
        }

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