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

#pragma once

#include "../datatypes/range1d.hpp"
#include "../result.hpp"

#include <array>
#include <cstdint>
#include <memory>

namespace rerun::components {
    /// **Component**: Range of expected or valid values, specifying a lower and upper bound.
    ///
    /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
    ///
    struct ValueRange {
        rerun::datatypes::Range1D range;

      public:
        ValueRange() = default;

        ValueRange(rerun::datatypes::Range1D range_) : range(range_) {}

        ValueRange& operator=(rerun::datatypes::Range1D range_) {
            range = range_;
            return *this;
        }

        ValueRange(std::array<double, 2> range_) : range(range_) {}

        ValueRange& operator=(std::array<double, 2> range_) {
            range = range_;
            return *this;
        }

        /// Cast to the underlying Range1D datatype
        operator rerun::datatypes::Range1D() const {
            return range;
        }
    };
} // namespace rerun::components

namespace rerun {
    static_assert(sizeof(rerun::datatypes::Range1D) == sizeof(components::ValueRange));

    /// \private
    template <>
    struct Loggable<components::ValueRange> {
        static constexpr std::string_view ComponentType = "rerun.components.ValueRange";

        /// Returns the arrow data type this type corresponds to.
        static const std::shared_ptr<arrow::DataType>& arrow_datatype() {
            return Loggable<rerun::datatypes::Range1D>::arrow_datatype();
        }

        /// Serializes an array of `rerun::components::ValueRange` into an arrow array.
        static Result<std::shared_ptr<arrow::Array>> to_arrow(
            const components::ValueRange* instances, size_t num_instances
        ) {
            if (num_instances == 0) {
                return Loggable<rerun::datatypes::Range1D>::to_arrow(nullptr, 0);
            } else if (instances == nullptr) {
                return rerun::Error(
                    ErrorCode::UnexpectedNullArgument,
                    "Passed array instances is null when num_elements> 0."
                );
            } else {
                return Loggable<rerun::datatypes::Range1D>::to_arrow(
                    &instances->range,
                    num_instances
                );
            }
        }
    };
} // namespace rerun
