// components/schema_org/common/metadata.mojom.cc 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.

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif

#include "components/schema_org/common/metadata.mojom.h"
#include <stdint.h>
#include <utility>
#include "base/notreached.h"
#include "mojo/public/cpp/bindings/lib/default_construct_tag_internal.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/bindings/mojo_buildflags.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"

#include "components/schema_org/common/metadata.mojom-params-data.h"
#include "components/schema_org/common/metadata.mojom-shared-message-ids.h"

#include "components/schema_org/common/metadata.mojom-import-headers.h"
#include "components/schema_org/common/metadata.mojom-test-utils.h"


namespace schema_org::mojom {
Property::Property()
    : name(),
      values() {}

Property::Property(
    const std::string& name_in,
    ValuesPtr values_in)
    : name(std::move(name_in)),
      values(std::move(values_in)) {}

Property::~Property() = default;

void Property::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "name"), this->name,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::string&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "values"), this->values,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type ValuesPtr>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool Property::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
Entity::Entity()
    : type(),
      properties() {}

Entity::Entity(
    const std::string& type_in,
    std::vector<PropertyPtr> properties_in)
    : type(std::move(type_in)),
      properties(std::move(properties_in)) {}

Entity::~Entity() = default;

void Entity::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "type"), this->type,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::string&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "properties"), this->properties,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type std::vector<PropertyPtr>>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool Entity::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
ValuesPtr
Values::NewBoolValues(
    std::vector<bool> value) {
  return ValuesPtr(
      std::in_place,
      std::in_place_index<static_cast<size_t>(Tag::kBoolValues)>,
      std::move(value));
}

ValuesPtr
Values::NewLongValues(
    std::vector<int64_t> value) {
  return ValuesPtr(
      std::in_place,
      std::in_place_index<static_cast<size_t>(Tag::kLongValues)>,
      std::move(value));
}

ValuesPtr
Values::NewStringValues(
    std::vector<std::string> value) {
  return ValuesPtr(
      std::in_place,
      std::in_place_index<static_cast<size_t>(Tag::kStringValues)>,
      std::move(value));
}

ValuesPtr
Values::NewEntityValues(
    std::vector<EntityPtr> value) {
  return ValuesPtr(
      std::in_place,
      std::in_place_index<static_cast<size_t>(Tag::kEntityValues)>,
      std::move(value));
}

Values::Values(
    std::in_place_index_t<static_cast<size_t>(Tag::kBoolValues)>,
    std::vector<bool> value)
    : tag_(Tag::kBoolValues),
      data_(std::in_place_index<static_cast<size_t>(Tag::kBoolValues)>,
            std::move(value)) {}

Values::Values(
    std::in_place_index_t<static_cast<size_t>(Tag::kLongValues)>,
    std::vector<int64_t> value)
    : tag_(Tag::kLongValues),
      data_(std::in_place_index<static_cast<size_t>(Tag::kLongValues)>,
            std::move(value)) {}

Values::Values(
    std::in_place_index_t<static_cast<size_t>(Tag::kStringValues)>,
    std::vector<std::string> value)
    : tag_(Tag::kStringValues),
      data_(std::in_place_index<static_cast<size_t>(Tag::kStringValues)>,
            std::move(value)) {}

Values::Values(
    std::in_place_index_t<static_cast<size_t>(Tag::kEntityValues)>,
    std::vector<EntityPtr> value)
    : tag_(Tag::kEntityValues),
      data_(std::in_place_index<static_cast<size_t>(Tag::kEntityValues)>,
            std::move(value)) {}
Values::~Values() {
  DestroyActive();
}

void Values::set_bool_values(std::vector<bool> bool_values) {
  if (tag_ == Tag::kBoolValues) {
    data_.bool_values = std::move(bool_values);
  } else {
    DestroyActive();
    tag_ = Tag::kBoolValues;
    new (&data_.bool_values) std::vector<bool>(
        std::move(bool_values));
  }
}

void Values::set_long_values(std::vector<int64_t> long_values) {
  if (tag_ == Tag::kLongValues) {
    data_.long_values = std::move(long_values);
  } else {
    DestroyActive();
    tag_ = Tag::kLongValues;
    new (&data_.long_values) std::vector<int64_t>(
        std::move(long_values));
  }
}

void Values::set_string_values(std::vector<std::string> string_values) {
  if (tag_ == Tag::kStringValues) {
    data_.string_values = std::move(string_values);
  } else {
    DestroyActive();
    tag_ = Tag::kStringValues;
    new (&data_.string_values) std::vector<std::string>(
        std::move(string_values));
  }
}

void Values::set_entity_values(std::vector<EntityPtr> entity_values) {
  if (tag_ == Tag::kEntityValues) {
    data_.entity_values = std::move(entity_values);
  } else {
    DestroyActive();
    tag_ = Tag::kEntityValues;
    new (&data_.entity_values) std::vector<EntityPtr>(
        std::move(entity_values));
  }
}


Values::Union_::Union_(
    std::in_place_index_t<static_cast<size_t>(Tag::kBoolValues)>,
    std::vector<bool> value)
    : bool_values(std::move(value)) {}

Values::Union_::Union_(
    std::in_place_index_t<static_cast<size_t>(Tag::kLongValues)>,
    std::vector<int64_t> value)
    : long_values(std::move(value)) {}

Values::Union_::Union_(
    std::in_place_index_t<static_cast<size_t>(Tag::kStringValues)>,
    std::vector<std::string> value)
    : string_values(std::move(value)) {}

Values::Union_::Union_(
    std::in_place_index_t<static_cast<size_t>(Tag::kEntityValues)>,
    std::vector<EntityPtr> value)
    : entity_values(std::move(value)) {}

void Values::DestroyActive() {
  switch (tag_) {

    case Tag::kBoolValues:
      std::destroy_at(&data_.bool_values);
      break;
    case Tag::kLongValues:
      std::destroy_at(&data_.long_values);
      break;
    case Tag::kStringValues:
      std::destroy_at(&data_.string_values);
      break;
    case Tag::kEntityValues:
      std::destroy_at(&data_.entity_values);
      break;
  }
}

bool Values::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context, false);
}


}  // schema_org::mojom


namespace mojo {


// static
bool StructTraits<::schema_org::mojom::Property::DataView, ::schema_org::mojom::PropertyPtr>::Read(
    ::schema_org::mojom::Property::DataView input,
    ::schema_org::mojom::PropertyPtr* output) {
  bool success = true;
  ::schema_org::mojom::PropertyPtr result(::schema_org::mojom::Property::New());
  
      if (success && !input.ReadName(&result->name))
        success = false;
      if (success && !input.ReadValues(&result->values))
        success = false;
  *output = std::move(result);
  return success;
}


// static
bool StructTraits<::schema_org::mojom::Entity::DataView, ::schema_org::mojom::EntityPtr>::Read(
    ::schema_org::mojom::Entity::DataView input,
    ::schema_org::mojom::EntityPtr* output) {
  bool success = true;
  ::schema_org::mojom::EntityPtr result(::schema_org::mojom::Entity::New());
  
      if (success && !input.ReadType(&result->type))
        success = false;
      if (success && !input.ReadProperties(&result->properties))
        success = false;
  *output = std::move(result);
  return success;
}

// static
bool UnionTraits<::schema_org::mojom::Values::DataView, ::schema_org::mojom::ValuesPtr>::Read(
    ::schema_org::mojom::Values::DataView input,
    ::schema_org::mojom::ValuesPtr* output) {
  using UnionType = ::schema_org::mojom::Values;
  using Tag = UnionType::Tag;

  switch (input.tag()) {
    case Tag::kBoolValues: {
      std::vector<bool> result_bool_values{};
      if (!input.ReadBoolValues(&result_bool_values))
        return false;

      *output = UnionType::NewBoolValues(
          std::move(result_bool_values));
      break;
    }
    case Tag::kLongValues: {
      std::vector<int64_t> result_long_values{};
      if (!input.ReadLongValues(&result_long_values))
        return false;

      *output = UnionType::NewLongValues(
          std::move(result_long_values));
      break;
    }
    case Tag::kStringValues: {
      std::vector<std::string> result_string_values{};
      if (!input.ReadStringValues(&result_string_values))
        return false;

      *output = UnionType::NewStringValues(
          std::move(result_string_values));
      break;
    }
    case Tag::kEntityValues: {
      std::vector<::schema_org::mojom::EntityPtr> result_entity_values{};
      if (!input.ReadEntityValues(&result_entity_values))
        return false;

      *output = UnionType::NewEntityValues(
          std::move(result_entity_values));
      break;
    }
    default:

      return false;
  }
  return true;
}

}  // namespace mojo


// Symbols declared in the -test-utils.h header are defined here instead of a
// separate .cc file to save compile time.


namespace schema_org::mojom {




}  // schema_org::mojom


#if defined(__clang__)
#pragma clang diagnostic pop
#endif