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

#include "dataframe_query.hpp"

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

namespace rerun::blueprint::archetypes {
    DataframeQuery DataframeQuery::clear_fields() {
        auto archetype = DataframeQuery();
        archetype.timeline =
            ComponentBatch::empty<rerun::blueprint::components::TimelineName>(Descriptor_timeline)
                .value_or_throw();
        archetype.filter_by_range =
            ComponentBatch::empty<rerun::blueprint::components::FilterByRange>(
                Descriptor_filter_by_range
            )
                .value_or_throw();
        archetype.filter_is_not_null =
            ComponentBatch::empty<rerun::blueprint::components::FilterIsNotNull>(
                Descriptor_filter_is_not_null
            )
                .value_or_throw();
        archetype.apply_latest_at =
            ComponentBatch::empty<rerun::blueprint::components::ApplyLatestAt>(
                Descriptor_apply_latest_at
            )
                .value_or_throw();
        archetype.select =
            ComponentBatch::empty<rerun::blueprint::components::SelectedColumns>(Descriptor_select)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> DataframeQuery::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(5);
        if (timeline.has_value()) {
            columns.push_back(timeline.value().partitioned(lengths_).value_or_throw());
        }
        if (filter_by_range.has_value()) {
            columns.push_back(filter_by_range.value().partitioned(lengths_).value_or_throw());
        }
        if (filter_is_not_null.has_value()) {
            columns.push_back(filter_is_not_null.value().partitioned(lengths_).value_or_throw());
        }
        if (apply_latest_at.has_value()) {
            columns.push_back(apply_latest_at.value().partitioned(lengths_).value_or_throw());
        }
        if (select.has_value()) {
            columns.push_back(select.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> DataframeQuery::columns() {
        if (timeline.has_value()) {
            return columns(std::vector<uint32_t>(timeline.value().length(), 1));
        }
        if (filter_by_range.has_value()) {
            return columns(std::vector<uint32_t>(filter_by_range.value().length(), 1));
        }
        if (filter_is_not_null.has_value()) {
            return columns(std::vector<uint32_t>(filter_is_not_null.value().length(), 1));
        }
        if (apply_latest_at.has_value()) {
            return columns(std::vector<uint32_t>(apply_latest_at.value().length(), 1));
        }
        if (select.has_value()) {
            return columns(std::vector<uint32_t>(select.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::blueprint::archetypes

namespace rerun {

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

        if (archetype.timeline.has_value()) {
            cells.push_back(archetype.timeline.value());
        }
        if (archetype.filter_by_range.has_value()) {
            cells.push_back(archetype.filter_by_range.value());
        }
        if (archetype.filter_is_not_null.has_value()) {
            cells.push_back(archetype.filter_is_not_null.value());
        }
        if (archetype.apply_latest_at.has_value()) {
            cells.push_back(archetype.apply_latest_at.value());
        }
        if (archetype.select.has_value()) {
            cells.push_back(archetype.select.value());
        }

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