// media/mojo/mojom/channel_layout.mojom-blink.h is auto generated by mojom_bindings_generator.py, do not edit

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_MOJO_MOJOM_CHANNEL_LAYOUT_MOJOM_BLINK_H_
#define MEDIA_MOJO_MOJOM_CHANNEL_LAYOUT_MOJOM_BLINK_H_

#include <stdint.h>

#include <limits>
#include <optional>
#include <type_traits>
#include <utility>
#include "mojo/public/cpp/bindings/clone_traits.h"
#include "mojo/public/cpp/bindings/equals_traits.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/cpp/bindings/union_traits.h"

#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"

#include "media/mojo/mojom/channel_layout.mojom-features.h"  // IWYU pragma: export
#include "media/mojo/mojom/channel_layout.mojom-shared.h"  // IWYU pragma: export
#include "media/mojo/mojom/channel_layout.mojom-blink-forward.h"  // IWYU pragma: export

#include "mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h"
#include "mojo/public/cpp/bindings/lib/wtf_hash_util.h"
#include "third_party/blink/renderer/platform/wtf/hash_functions.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"




#include "media/mojo/mojom/media_types_enum_mojom_traits.h"
#include "third_party/blink/public/platform/web_common.h"
#if !BLINK_MOJO_IMPL && !INSIDE_BLINK
#error "File must only be imported inside blink"
#endif




namespace media::mojom::blink {





class BLINK_PLATFORM_EXPORT ChannelLayoutConfig {
 public:
  using DataView = ChannelLayoutConfigDataView;
  using Data_ = internal::ChannelLayoutConfig_Data;
  using Tag = Data_::ChannelLayoutConfig_Tag;

  template <typename... Args>
  static ChannelLayoutConfigPtr New(Args&&... args) {
    static_assert(
        sizeof...(args) < 0,
        "Do not use Union::New(); to create a union of a given subtype, use "
        "New<SubType>(), not New() followed by set_<sub_type>(). To represent "
        "an empty union, mark the field or parameter as nullable in the mojom "
        "definition.");
    return nullptr;
  }

  // Construct an instance holding |predefined_layout|.
  static ChannelLayoutConfigPtr NewPredefinedLayout(
      ::media::ChannelLayout value);
  // Construct an instance holding |discrete_channels|.
  static ChannelLayoutConfigPtr NewDiscreteChannels(
      uint32_t value);

  template <typename U>
  static ChannelLayoutConfigPtr From(const U& u) {
    return mojo::TypeConverter<ChannelLayoutConfigPtr, U>::Convert(u);
  }

  template <typename U>
  U To() const {
    return mojo::TypeConverter<U, ChannelLayoutConfig>::Convert(*this);
  }
  ~ChannelLayoutConfig();


  // Clone() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Clone() or copy
  // constructor/assignment are available for members.
  template <typename UnionPtrType = ChannelLayoutConfigPtr>
  ChannelLayoutConfigPtr Clone() const;

  // Equals() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Equals() or == operator
  // are available for members.
  template <typename T,
            typename std::enable_if<std::is_same<
                T, ChannelLayoutConfig>::value>::type* = nullptr>
  bool Equals(const T& other) const;

  template <typename T,
            typename std::enable_if<std::is_same<
                T, ChannelLayoutConfig>::value>::type* = nullptr>
  bool operator==(const T& rhs) const { return Equals(rhs); }

  Tag which() const {
    return tag_;
  }

  bool is_predefined_layout() const { return tag_ == Tag::kPredefinedLayout; }
  ::media::ChannelLayout get_predefined_layout() const {
    CHECK(tag_ == Tag::kPredefinedLayout);
    return data_.predefined_layout;
  }
  void set_predefined_layout(::media::ChannelLayout predefined_layout);

  bool is_discrete_channels() const { return tag_ == Tag::kDiscreteChannels; }
  uint32_t get_discrete_channels() const {
    CHECK(tag_ == Tag::kDiscreteChannels);
    return data_.discrete_channels;
  }
  void set_discrete_channels(uint32_t discrete_channels);

  template <typename UserType>
  static mojo::Message SerializeAsMessage(UserType* input) {
    return mojo::internal::SerializeAsMessageImpl<
        ChannelLayoutConfig::DataView>(input);
  }

  template <typename UserType>
  static bool DeserializeFromMessage(mojo::Message input,
                                     UserType* output) {
    return mojo::internal::DeserializeImpl<ChannelLayoutConfig::DataView>(
        input, input.payload(), input.payload_num_bytes(), output, Validate);
  }

 private:
  template <typename T>
  friend class ::mojo::InlinedStructPtr;
  template <typename T>
  friend class ::mojo::StructPtr;

  union Union_ {
    Union_(
        std::in_place_index_t<static_cast<size_t>(Tag::kPredefinedLayout)>,
        ::media::ChannelLayout value);
    Union_(
        std::in_place_index_t<static_cast<size_t>(Tag::kDiscreteChannels)>,
        uint32_t value);
    // The contents of the union are explicitly destroyed by `DestroyActive()`.
    ~Union_() {}

    ::media::ChannelLayout predefined_layout;
    uint32_t discrete_channels;
  };

  ChannelLayoutConfig(
      std::in_place_index_t<static_cast<size_t>(Tag::kPredefinedLayout)>,
      ::media::ChannelLayout value);
  ChannelLayoutConfig(
      std::in_place_index_t<static_cast<size_t>(Tag::kDiscreteChannels)>,
      uint32_t value);

  static bool Validate(const void* data,
                       mojo::internal::ValidationContext* validation_context);

  void DestroyActive();
  Tag tag_;
  Union_ data_;
};

template <typename UnionPtrType>
ChannelLayoutConfigPtr ChannelLayoutConfig::Clone() const {
  switch (tag_) {
    case Tag::kPredefinedLayout:
      return NewPredefinedLayout(
          mojo::Clone(data_.predefined_layout));
    case Tag::kDiscreteChannels:
      return NewDiscreteChannels(
          mojo::Clone(data_.discrete_channels));
  }
  return nullptr;
}

template <typename T,
          typename std::enable_if<std::is_same<
              T, ChannelLayoutConfig>::value>::type*>
bool ChannelLayoutConfig::Equals(const T& other) const {
  if (tag_ != other.which())
    return false;

  switch (tag_) {
    case Tag::kPredefinedLayout:
      return mojo::Equals(data_.predefined_layout, other.data_.predefined_layout);
    case Tag::kDiscreteChannels:
      return mojo::Equals(data_.discrete_channels, other.data_.discrete_channels);
  }

  return false;
}


}  // media::mojom::blink

namespace mojo {


template <>
struct BLINK_PLATFORM_EXPORT UnionTraits<::media::mojom::blink::ChannelLayoutConfig::DataView,
                                        ::media::mojom::blink::ChannelLayoutConfigPtr> {
  static bool IsNull(const ::media::mojom::blink::ChannelLayoutConfigPtr& input) { return !input; }
  static void SetToNull(::media::mojom::blink::ChannelLayoutConfigPtr* output) { output->reset(); }

  static ::media::mojom::blink::ChannelLayoutConfig::Tag GetTag(const ::media::mojom::blink::ChannelLayoutConfigPtr& input) {
    return input->which();
  }

  static  ::media::ChannelLayout predefined_layout(const ::media::mojom::blink::ChannelLayoutConfigPtr& input) {
    return input->get_predefined_layout();
  }

  static  uint32_t discrete_channels(const ::media::mojom::blink::ChannelLayoutConfigPtr& input) {
    return input->get_discrete_channels();
  }

  static bool Read(::media::mojom::blink::ChannelLayoutConfig::DataView input, ::media::mojom::blink::ChannelLayoutConfigPtr* output);
};

}  // namespace mojo

#endif  // MEDIA_MOJO_MOJOM_CHANNEL_LAYOUT_MOJOM_BLINK_H_