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

#pragma once

#include "../../blueprint/components/corner2d.hpp"
#include "../../collection.hpp"
#include "../../component_batch.hpp"
#include "../../component_column.hpp"
#include "../../components/visible.hpp"
#include "../../result.hpp"

#include <cstdint>
#include <optional>
#include <utility>
#include <vector>

namespace rerun::blueprint::archetypes {
    /// **Archetype**: Configuration for the legend of a plot.
    ///
    /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
    ///
    struct PlotLegend {
        /// To what corner the legend is aligned.
        ///
        /// Defaults to the right bottom corner.
        std::optional<ComponentBatch> corner;

        /// Whether the legend is shown at all.
        ///
        /// True by default.
        std::optional<ComponentBatch> visible;

      public:
        /// The name of the archetype as used in `ComponentDescriptor`s.
        static constexpr const char ArchetypeName[] = "rerun.blueprint.archetypes.PlotLegend";

        /// `ComponentDescriptor` for the `corner` field.
        static constexpr auto Descriptor_corner = ComponentDescriptor(
            ArchetypeName, "PlotLegend:corner",
            Loggable<rerun::blueprint::components::Corner2D>::ComponentType
        );
        /// `ComponentDescriptor` for the `visible` field.
        static constexpr auto Descriptor_visible = ComponentDescriptor(
            ArchetypeName, "PlotLegend:visible", Loggable<rerun::components::Visible>::ComponentType
        );

      public:
        PlotLegend() = default;
        PlotLegend(PlotLegend&& other) = default;
        PlotLegend(const PlotLegend& other) = default;
        PlotLegend& operator=(const PlotLegend& other) = default;
        PlotLegend& operator=(PlotLegend&& other) = default;

        /// Update only some specific fields of a `PlotLegend`.
        static PlotLegend update_fields() {
            return PlotLegend();
        }

        /// Clear all the fields of a `PlotLegend`.
        static PlotLegend clear_fields();

        /// To what corner the legend is aligned.
        ///
        /// Defaults to the right bottom corner.
        PlotLegend with_corner(const rerun::blueprint::components::Corner2D& _corner) && {
            corner = ComponentBatch::from_loggable(_corner, Descriptor_corner).value_or_throw();
            return std::move(*this);
        }

        /// Whether the legend is shown at all.
        ///
        /// True by default.
        PlotLegend with_visible(const rerun::components::Visible& _visible) && {
            visible = ComponentBatch::from_loggable(_visible, Descriptor_visible).value_or_throw();
            return std::move(*this);
        }

        /// Partitions the component data into multiple sub-batches.
        ///
        /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
        /// instead, via `ComponentBatch::partitioned`.
        ///
        /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
        ///
        /// The specified `lengths` must sum to the total length of the component batch.
        Collection<ComponentColumn> columns(const Collection<uint32_t>& lengths_);

        /// Partitions the component data into unit-length sub-batches.
        ///
        /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
        /// where `n` is automatically guessed.
        Collection<ComponentColumn> columns();
    };

} // namespace rerun::blueprint::archetypes

namespace rerun {
    /// \private
    template <typename T>
    struct AsComponents;

    /// \private
    template <>
    struct AsComponents<blueprint::archetypes::PlotLegend> {
        /// Serialize all set component batches.
        static Result<Collection<ComponentBatch>> as_batches(
            const blueprint::archetypes::PlotLegend& archetype
        );
    };
} // namespace rerun
