// third_party/blink/public/mojom/frame/agent_cluster_key.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 THIRD_PARTY_BLINK_PUBLIC_MOJOM_FRAME_AGENT_CLUSTER_KEY_MOJOM_BLINK_H_
#define THIRD_PARTY_BLINK_PUBLIC_MOJOM_FRAME_AGENT_CLUSTER_KEY_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 "mojo/public/cpp/bindings/lib/serialization.h"

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

#include "third_party/blink/public/mojom/frame/agent_cluster_key.mojom-features.h"  // IWYU pragma: export
#include "third_party/blink/public/mojom/frame/agent_cluster_key.mojom-shared.h"  // IWYU pragma: export
#include "third_party/blink/public/mojom/frame/agent_cluster_key.mojom-blink-forward.h"  // IWYU pragma: export
#include "url/mojom/origin.mojom-blink.h"
#include "url/mojom/url.mojom-blink.h"

#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 "third_party/blink/renderer/core/core_export.h"
#if !BLINK_MOJO_IMPL && !INSIDE_BLINK
#error "File must only be imported inside blink"
#endif




namespace blink::mojom::blink {







class CORE_EXPORT AgentClusterKey {
 public:
  using DataView = AgentClusterKeyDataView;
  using Data_ = internal::AgentClusterKey_Data;
  using Tag = Data_::AgentClusterKey_Tag;

  template <typename... Args>
  static AgentClusterKeyPtr 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 |site_key|.
  static AgentClusterKeyPtr NewSiteKey(
      const ::blink::KURL& value);
  // Construct an instance holding |origin_key|.
  static AgentClusterKeyPtr NewOriginKey(
      OriginKeyedAgentClusterKeyPtr value);

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

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

  // Delete the copy constructor and copy assignment operators because `data_`
  // contains raw pointers that must not be copied.
  AgentClusterKey(const AgentClusterKey& other) = delete;
  AgentClusterKey& operator=(const AgentClusterKey& other) = delete;

  // 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 = AgentClusterKeyPtr>
  AgentClusterKeyPtr 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, AgentClusterKey>::value>::type* = nullptr>
  bool Equals(const T& other) const;

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

  Tag which() const {
    return tag_;
  }

  bool is_site_key() const { return tag_ == Tag::kSiteKey; }
  const ::blink::KURL& get_site_key() const {
    CHECK(tag_ == Tag::kSiteKey);
    return data_.site_key;
  }
  ::blink::KURL& get_site_key() {
    CHECK(tag_ == Tag::kSiteKey);
    return data_.site_key;
  }
  void set_site_key(const ::blink::KURL& site_key);

  bool is_origin_key() const { return tag_ == Tag::kOriginKey; }
  const OriginKeyedAgentClusterKeyPtr& get_origin_key() const {
    CHECK(tag_ == Tag::kOriginKey);
    return data_.origin_key;
  }
  OriginKeyedAgentClusterKeyPtr& get_origin_key() {
    CHECK(tag_ == Tag::kOriginKey);
    return data_.origin_key;
  }
  void set_origin_key(OriginKeyedAgentClusterKeyPtr origin_key);

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

  template <typename UserType>
  static bool DeserializeFromMessage(mojo::Message input,
                                     UserType* output) {
    return mojo::internal::DeserializeImpl<AgentClusterKey::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::kSiteKey)>,
        const ::blink::KURL& value);
    Union_(
        std::in_place_index_t<static_cast<size_t>(Tag::kOriginKey)>,
        OriginKeyedAgentClusterKeyPtr value);
    // The contents of the union are explicitly destroyed by `DestroyActive()`.
    ~Union_() {}

    ::blink::KURL site_key;
    OriginKeyedAgentClusterKeyPtr origin_key;
  };

  AgentClusterKey(
      std::in_place_index_t<static_cast<size_t>(Tag::kSiteKey)>,
      const ::blink::KURL& value);
  AgentClusterKey(
      std::in_place_index_t<static_cast<size_t>(Tag::kOriginKey)>,
      OriginKeyedAgentClusterKeyPtr value);

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

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





class CORE_EXPORT CrossOriginIsolationKey {
 public:
  template <typename T>
  using EnableIfSame = std::enable_if_t<std::is_same<CrossOriginIsolationKey, T>::value>;
  using DataView = CrossOriginIsolationKeyDataView;
  using Data_ = internal::CrossOriginIsolationKey_Data;

  template <typename... Args>
  static CrossOriginIsolationKeyPtr New(Args&&... args) {
    return CrossOriginIsolationKeyPtr(
        std::in_place, std::forward<Args>(args)...);
  }

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

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


  CrossOriginIsolationKey();

  CrossOriginIsolationKey(
      const ::scoped_refptr<const ::blink::SecurityOrigin>& common_origin,
      CrossOriginIsolationMode mode);


  ~CrossOriginIsolationKey();

  // 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 StructPtrType = CrossOriginIsolationKeyPtr>
  CrossOriginIsolationKeyPtr 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, CrossOriginIsolationKey::EnableIfSame<T>* = nullptr>
  bool Equals(const T& other) const;

  template <typename T, CrossOriginIsolationKey::EnableIfSame<T>* = nullptr>
  bool operator==(const T& rhs) const { return Equals(rhs); }

  template <typename T, CrossOriginIsolationKey::EnableIfSame<T>* = nullptr>
  bool operator!=(const T& rhs) const { return !operator==(rhs); }

  template <mojo::internal::SendValidation send_validation, typename UserType>
  static ::blink::Vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        CrossOriginIsolationKey::DataView, ::blink::Vector<uint8_t>, send_validation>(input);
  }

  template <typename UserType>
  static ::blink::Vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        CrossOriginIsolationKey::DataView, ::blink::Vector<uint8_t>>(input);
  }

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

  // The returned Message is serialized only if the message is moved
  // cross-process or cross-language. Otherwise if the message is Deserialized
  // as the same UserType |input| will just be moved to |output| in
  // DeserializeFromMessage.
  template <typename UserType>
  static mojo::Message WrapAsMessage(UserType input) {
    return mojo::Message(std::make_unique<
        internal::CrossOriginIsolationKey_UnserializedMessageContext<
            UserType, CrossOriginIsolationKey::DataView>>(0, 0, std::move(input)),
        MOJO_CREATE_MESSAGE_FLAG_NONE);
  }

  template <typename UserType>
  static bool Deserialize(const void* data,
                          size_t data_num_bytes,
                          UserType* output) {
    mojo::Message message;
    return mojo::internal::DeserializeImpl<CrossOriginIsolationKey::DataView>(
        message, data, data_num_bytes, output, Validate);
  }

  template <typename UserType>
  static bool Deserialize(base::span<const uint8_t> input,
                          UserType* output) {
    return CrossOriginIsolationKey::Deserialize(
        input.empty() ? nullptr : input.data(), input.size(), output);
  }

  template <typename UserType>
  static bool DeserializeFromMessage(mojo::Message input,
                                     UserType* output) {
    auto context = input.TakeUnserializedContext<
        internal::CrossOriginIsolationKey_UnserializedMessageContext<
            UserType, CrossOriginIsolationKey::DataView>>();
    if (context) {
      *output = std::move(context->TakeData());
      return true;
    }
    input.SerializeIfNecessary();
    return mojo::internal::DeserializeImpl<CrossOriginIsolationKey::DataView>(
        input, input.payload(), input.payload_num_bytes(), output, Validate);
  }

  
  ::scoped_refptr<const ::blink::SecurityOrigin> common_origin;
  
  CrossOriginIsolationMode mode;

  // Serialise this struct into a trace.
  void WriteIntoTrace(perfetto::TracedValue traced_context) const;

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

// The comparison operators are templates, so they are only instantiated if they
// are used. Thus, the bindings generator does not need to know whether
// comparison operators are available for members.
template <typename T, CrossOriginIsolationKey::EnableIfSame<T>* = nullptr>
bool operator<(const T& lhs, const T& rhs);

template <typename T, CrossOriginIsolationKey::EnableIfSame<T>* = nullptr>
bool operator<=(const T& lhs, const T& rhs) {
  return !(rhs < lhs);
}

template <typename T, CrossOriginIsolationKey::EnableIfSame<T>* = nullptr>
bool operator>(const T& lhs, const T& rhs) {
  return rhs < lhs;
}

template <typename T, CrossOriginIsolationKey::EnableIfSame<T>* = nullptr>
bool operator>=(const T& lhs, const T& rhs) {
  return !(lhs < rhs);
}





class CORE_EXPORT OriginKeyedAgentClusterKey {
 public:
  template <typename T>
  using EnableIfSame = std::enable_if_t<std::is_same<OriginKeyedAgentClusterKey, T>::value>;
  using DataView = OriginKeyedAgentClusterKeyDataView;
  using Data_ = internal::OriginKeyedAgentClusterKey_Data;

  template <typename... Args>
  static OriginKeyedAgentClusterKeyPtr New(Args&&... args) {
    return OriginKeyedAgentClusterKeyPtr(
        std::in_place, std::forward<Args>(args)...);
  }

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

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


  OriginKeyedAgentClusterKey();

  OriginKeyedAgentClusterKey(
      const ::scoped_refptr<const ::blink::SecurityOrigin>& origin,
      CrossOriginIsolationKeyPtr isolation_key);

OriginKeyedAgentClusterKey(const OriginKeyedAgentClusterKey&) = delete;
OriginKeyedAgentClusterKey& operator=(const OriginKeyedAgentClusterKey&) = delete;

  ~OriginKeyedAgentClusterKey();

  // 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 StructPtrType = OriginKeyedAgentClusterKeyPtr>
  OriginKeyedAgentClusterKeyPtr 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, OriginKeyedAgentClusterKey::EnableIfSame<T>* = nullptr>
  bool Equals(const T& other) const;

  template <typename T, OriginKeyedAgentClusterKey::EnableIfSame<T>* = nullptr>
  bool operator==(const T& rhs) const { return Equals(rhs); }

  template <typename T, OriginKeyedAgentClusterKey::EnableIfSame<T>* = nullptr>
  bool operator!=(const T& rhs) const { return !operator==(rhs); }

  template <mojo::internal::SendValidation send_validation, typename UserType>
  static ::blink::Vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        OriginKeyedAgentClusterKey::DataView, ::blink::Vector<uint8_t>, send_validation>(input);
  }

  template <typename UserType>
  static ::blink::Vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        OriginKeyedAgentClusterKey::DataView, ::blink::Vector<uint8_t>>(input);
  }

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

  // The returned Message is serialized only if the message is moved
  // cross-process or cross-language. Otherwise if the message is Deserialized
  // as the same UserType |input| will just be moved to |output| in
  // DeserializeFromMessage.
  template <typename UserType>
  static mojo::Message WrapAsMessage(UserType input) {
    return mojo::Message(std::make_unique<
        internal::OriginKeyedAgentClusterKey_UnserializedMessageContext<
            UserType, OriginKeyedAgentClusterKey::DataView>>(0, 0, std::move(input)),
        MOJO_CREATE_MESSAGE_FLAG_NONE);
  }

  template <typename UserType>
  static bool Deserialize(const void* data,
                          size_t data_num_bytes,
                          UserType* output) {
    mojo::Message message;
    return mojo::internal::DeserializeImpl<OriginKeyedAgentClusterKey::DataView>(
        message, data, data_num_bytes, output, Validate);
  }

  template <typename UserType>
  static bool Deserialize(base::span<const uint8_t> input,
                          UserType* output) {
    return OriginKeyedAgentClusterKey::Deserialize(
        input.empty() ? nullptr : input.data(), input.size(), output);
  }

  template <typename UserType>
  static bool DeserializeFromMessage(mojo::Message input,
                                     UserType* output) {
    auto context = input.TakeUnserializedContext<
        internal::OriginKeyedAgentClusterKey_UnserializedMessageContext<
            UserType, OriginKeyedAgentClusterKey::DataView>>();
    if (context) {
      *output = std::move(context->TakeData());
      return true;
    }
    input.SerializeIfNecessary();
    return mojo::internal::DeserializeImpl<OriginKeyedAgentClusterKey::DataView>(
        input, input.payload(), input.payload_num_bytes(), output, Validate);
  }

  
  ::scoped_refptr<const ::blink::SecurityOrigin> origin;
  
  CrossOriginIsolationKeyPtr isolation_key;

  // Serialise this struct into a trace.
  void WriteIntoTrace(perfetto::TracedValue traced_context) const;

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

// The comparison operators are templates, so they are only instantiated if they
// are used. Thus, the bindings generator does not need to know whether
// comparison operators are available for members.
template <typename T, OriginKeyedAgentClusterKey::EnableIfSame<T>* = nullptr>
bool operator<(const T& lhs, const T& rhs);

template <typename T, OriginKeyedAgentClusterKey::EnableIfSame<T>* = nullptr>
bool operator<=(const T& lhs, const T& rhs) {
  return !(rhs < lhs);
}

template <typename T, OriginKeyedAgentClusterKey::EnableIfSame<T>* = nullptr>
bool operator>(const T& lhs, const T& rhs) {
  return rhs < lhs;
}

template <typename T, OriginKeyedAgentClusterKey::EnableIfSame<T>* = nullptr>
bool operator>=(const T& lhs, const T& rhs) {
  return !(lhs < rhs);
}

template <typename UnionPtrType>
AgentClusterKeyPtr AgentClusterKey::Clone() const {
  switch (tag_) {
    case Tag::kSiteKey:
      return NewSiteKey(
          mojo::Clone(data_.site_key));
    case Tag::kOriginKey:
      return NewOriginKey(
          mojo::Clone(data_.origin_key));
  }
  return nullptr;
}

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

  switch (tag_) {
    case Tag::kSiteKey:
      return mojo::Equals(data_.site_key, other.data_.site_key);
    case Tag::kOriginKey:
      return mojo::Equals(data_.origin_key, other.data_.origin_key);
  }

  return false;
}
template <typename StructPtrType>
CrossOriginIsolationKeyPtr CrossOriginIsolationKey::Clone() const {
  return New(
      mojo::Clone(common_origin),
      mojo::Clone(mode)
  );
}

template <typename T, CrossOriginIsolationKey::EnableIfSame<T>*>
bool CrossOriginIsolationKey::Equals(const T& other_struct) const {
  if (!mojo::Equals(this->common_origin, other_struct.common_origin))
    return false;
  if (!mojo::Equals(this->mode, other_struct.mode))
    return false;
  return true;
}

template <typename T, CrossOriginIsolationKey::EnableIfSame<T>*>
bool operator<(const T& lhs, const T& rhs) {
  if (lhs.common_origin < rhs.common_origin)
    return true;
  if (rhs.common_origin < lhs.common_origin)
    return false;
  if (lhs.mode < rhs.mode)
    return true;
  if (rhs.mode < lhs.mode)
    return false;
  return false;
}
template <typename StructPtrType>
OriginKeyedAgentClusterKeyPtr OriginKeyedAgentClusterKey::Clone() const {
  return New(
      mojo::Clone(origin),
      mojo::Clone(isolation_key)
  );
}

template <typename T, OriginKeyedAgentClusterKey::EnableIfSame<T>*>
bool OriginKeyedAgentClusterKey::Equals(const T& other_struct) const {
  if (!mojo::Equals(this->origin, other_struct.origin))
    return false;
  if (!mojo::Equals(this->isolation_key, other_struct.isolation_key))
    return false;
  return true;
}

template <typename T, OriginKeyedAgentClusterKey::EnableIfSame<T>*>
bool operator<(const T& lhs, const T& rhs) {
  if (lhs.origin < rhs.origin)
    return true;
  if (rhs.origin < lhs.origin)
    return false;
  if (lhs.isolation_key < rhs.isolation_key)
    return true;
  if (rhs.isolation_key < lhs.isolation_key)
    return false;
  return false;
}


}  // blink::mojom::blink

namespace mojo {


template <>
struct CORE_EXPORT StructTraits<::blink::mojom::blink::CrossOriginIsolationKey::DataView,
                                         ::blink::mojom::blink::CrossOriginIsolationKeyPtr> {
  static bool IsNull(const ::blink::mojom::blink::CrossOriginIsolationKeyPtr& input) { return !input; }
  static void SetToNull(::blink::mojom::blink::CrossOriginIsolationKeyPtr* output) { output->reset(); }

  static const decltype(::blink::mojom::blink::CrossOriginIsolationKey::common_origin)& common_origin(
      const ::blink::mojom::blink::CrossOriginIsolationKeyPtr& input) {
    return input->common_origin;
  }

  static decltype(::blink::mojom::blink::CrossOriginIsolationKey::mode) mode(
      const ::blink::mojom::blink::CrossOriginIsolationKeyPtr& input) {
    return input->mode;
  }

  static bool Read(::blink::mojom::blink::CrossOriginIsolationKey::DataView input, ::blink::mojom::blink::CrossOriginIsolationKeyPtr* output);
};


template <>
struct CORE_EXPORT StructTraits<::blink::mojom::blink::OriginKeyedAgentClusterKey::DataView,
                                         ::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr> {
  static bool IsNull(const ::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr& input) { return !input; }
  static void SetToNull(::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr* output) { output->reset(); }

  static const decltype(::blink::mojom::blink::OriginKeyedAgentClusterKey::origin)& origin(
      const ::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr& input) {
    return input->origin;
  }

  static const decltype(::blink::mojom::blink::OriginKeyedAgentClusterKey::isolation_key)& isolation_key(
      const ::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr& input) {
    return input->isolation_key;
  }

  static bool Read(::blink::mojom::blink::OriginKeyedAgentClusterKey::DataView input, ::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr* output);
};


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

  static ::blink::mojom::blink::AgentClusterKey::Tag GetTag(const ::blink::mojom::blink::AgentClusterKeyPtr& input) {
    return input->which();
  }

  static const ::blink::KURL& site_key(const ::blink::mojom::blink::AgentClusterKeyPtr& input) {
    return input->get_site_key();
  }

  static const ::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr& origin_key(const ::blink::mojom::blink::AgentClusterKeyPtr& input) {
    return input->get_origin_key();
  }

  static bool Read(::blink::mojom::blink::AgentClusterKey::DataView input, ::blink::mojom::blink::AgentClusterKeyPtr* output);
};

}  // namespace mojo

#endif  // THIRD_PARTY_BLINK_PUBLIC_MOJOM_FRAME_AGENT_CLUSTER_KEY_MOJOM_BLINK_H_