// third_party/blink/public/mojom/ai/ai_common.mojom-shared.cc is auto generated by mojom_bindings_generator.py, do not edit

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

#include "third_party/blink/public/mojom/ai/ai_common.mojom-shared.h"
#include <ostream>
#include <utility>
#include "base/strings/stringprintf.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/bindings/lib/validation_util.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"

#include "third_party/blink/public/mojom/ai/ai_common.mojom-params-data.h"
namespace blink {
namespace mojom {

NOINLINE static const char* AIManagerCreateClientErrorToStringHelper(AIManagerCreateClientError value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case AIManagerCreateClientError::kUnableToCreateSession:
      return "kUnableToCreateSession";
    case AIManagerCreateClientError::kUnableToCalculateTokenSize:
      return "kUnableToCalculateTokenSize";
    case AIManagerCreateClientError::kInitialInputTooLarge:
      return "kInitialInputTooLarge";
    default:
      return nullptr;
  }
}

std::string AIManagerCreateClientErrorToString(AIManagerCreateClientError value) {
  const char *str = AIManagerCreateClientErrorToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown AIManagerCreateClientError value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, AIManagerCreateClientError value) {
  return os << AIManagerCreateClientErrorToString(value);
}

namespace internal {


// static
bool AILanguageCode_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 16, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const AILanguageCode_Data* object =
      static_cast<const AILanguageCode_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->code, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& code_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->code, validation_context,
                                         &code_validate_params)) {
    return false;
  }

  return true;
}

AILanguageCode_Data::AILanguageCode_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool QuotaErrorInfo_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 16, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const QuotaErrorInfo_Data* object =
      static_cast<const QuotaErrorInfo_Data*>(data);

  return true;
}

QuotaErrorInfo_Data::QuotaErrorInfo_Data()
    : header_({sizeof(*this), 0}) {}

}  // namespace internal
}  // namespace mojom
}  // namespace blink

namespace perfetto {

// static
void TraceFormatTraits<::blink::mojom::AIManagerCreateClientError>::WriteIntoTrace(
   perfetto::TracedValue context, ::blink::mojom::AIManagerCreateClientError value) {
  return std::move(context).WriteString(::blink::mojom::AIManagerCreateClientErrorToString(value));
}

} // namespace perfetto