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

#include "tensor_scalar_mapping.hpp"

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

namespace rerun::blueprint::archetypes {
    TensorScalarMapping TensorScalarMapping::clear_fields() {
        auto archetype = TensorScalarMapping();
        archetype.mag_filter =
            ComponentBatch::empty<rerun::components::MagnificationFilter>(Descriptor_mag_filter)
                .value_or_throw();
        archetype.colormap = ComponentBatch::empty<rerun::components::Colormap>(Descriptor_colormap)
                                 .value_or_throw();
        archetype.gamma =
            ComponentBatch::empty<rerun::components::GammaCorrection>(Descriptor_gamma)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> TensorScalarMapping::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(3);
        if (mag_filter.has_value()) {
            columns.push_back(mag_filter.value().partitioned(lengths_).value_or_throw());
        }
        if (colormap.has_value()) {
            columns.push_back(colormap.value().partitioned(lengths_).value_or_throw());
        }
        if (gamma.has_value()) {
            columns.push_back(gamma.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> TensorScalarMapping::columns() {
        if (mag_filter.has_value()) {
            return columns(std::vector<uint32_t>(mag_filter.value().length(), 1));
        }
        if (colormap.has_value()) {
            return columns(std::vector<uint32_t>(colormap.value().length(), 1));
        }
        if (gamma.has_value()) {
            return columns(std::vector<uint32_t>(gamma.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::blueprint::archetypes

namespace rerun {

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

        if (archetype.mag_filter.has_value()) {
            cells.push_back(archetype.mag_filter.value());
        }
        if (archetype.colormap.has_value()) {
            cells.push_back(archetype.colormap.value());
        }
        if (archetype.gamma.has_value()) {
            cells.push_back(archetype.gamma.value());
        }

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