// Copyright (c) 2026 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=1df614086d5856dfe7e779f5d24881d218f75b64$
//

#include <algorithm>

#include "libcef_dll/cpptoc/component_update_callback_cpptoc.h"
#include "libcef_dll/ctocpp/component_ctocpp.h"
#include "libcef_dll/ctocpp/component_updater_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"

#if CEF_API_ADDED(14600)

// STATIC METHODS - Body may be edited by hand.

NO_SANITIZE("cfi-icall")
CefRefPtr<CefComponentUpdater> CefComponentUpdater::GetComponentUpdater() {
  shutdown_checker::AssertNotShutdown();

  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  // Execute
  auto *_retval = cef_component_updater_get();

  // Return type: refptr_same
  return CefComponentUpdaterCToCpp_Wrap(_retval);
}

// VIRTUAL METHODS - Body may be edited by hand.

NO_SANITIZE("cfi-icall") size_t CefComponentUpdaterCToCpp::GetComponentCount() {
  shutdown_checker::AssertNotShutdown();

  auto *_struct = GetStruct();
  if (!_struct->get_component_count) {
    return 0;
  }

  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  // Execute
  size_t _retval = _struct->get_component_count(_struct);

  // Return type: simple
  return _retval;
}

NO_SANITIZE("cfi-icall")
void CefComponentUpdaterCToCpp::GetComponents(
    std::vector<CefRefPtr<CefComponent>> &components) {
  shutdown_checker::AssertNotShutdown();

  auto *_struct = GetStruct();
  if (!_struct->get_components) {
    return;
  }

  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  // Translate param: components; type: refptr_vec_same_byref
  size_t componentsSize = components.size();
  size_t componentsCount = std::max(GetComponentCount(), componentsSize);
  cef_component_t **componentsList = NULL;
  if (componentsCount > 0) {
    componentsList = new cef_component_t *[componentsCount];
    DCHECK(componentsList);
    if (componentsList) {
      memset(componentsList, 0, sizeof(cef_component_t *) * componentsCount);
    }
    if (componentsList && componentsSize > 0) {
      for (size_t i = 0; i < componentsSize; ++i) {
        componentsList[i] = CefComponentCToCpp_Unwrap(components[i]);
      }
    }
  }

  // Execute
  _struct->get_components(_struct, &componentsCount, componentsList);

  // Restore param:components; type: refptr_vec_same_byref
  components.clear();
  if (componentsCount > 0 && componentsList) {
    for (size_t i = 0; i < componentsCount; ++i) {
      components.push_back(CefComponentCToCpp_Wrap(componentsList[i]));
    }
    delete[] componentsList;
  }
}

NO_SANITIZE("cfi-icall")
CefRefPtr<CefComponent> CefComponentUpdaterCToCpp::GetComponentByID(
    const CefString &component_id) {
  shutdown_checker::AssertNotShutdown();

  auto *_struct = GetStruct();
  if (!_struct->get_component_by_id) {
    return nullptr;
  }

  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  // Verify param: component_id; type: string_byref_const
  DCHECK(!component_id.empty());
  if (component_id.empty()) {
    return nullptr;
  }

  // Execute
  auto *_retval =
      _struct->get_component_by_id(_struct, component_id.GetStruct());

  // Return type: refptr_same
  return CefComponentCToCpp_Wrap(_retval);
}

NO_SANITIZE("cfi-icall")
void CefComponentUpdaterCToCpp::Update(
    const CefString &component_id, cef_component_update_priority_t priority,
    CefRefPtr<CefComponentUpdateCallback> callback) {
  shutdown_checker::AssertNotShutdown();

  auto *_struct = GetStruct();
  if (!_struct->update) {
    return;
  }

  // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

  // Verify param: component_id; type: string_byref_const
  DCHECK(!component_id.empty());
  if (component_id.empty()) {
    return;
  }
  // Unverified params: callback

  // Execute
  _struct->update(_struct, component_id.GetStruct(), priority,
                  CefComponentUpdateCallbackCppToC_Wrap(callback));
}

// CONSTRUCTOR - Do not edit by hand.

CefComponentUpdaterCToCpp::CefComponentUpdaterCToCpp() {}

// DESTRUCTOR - Do not edit by hand.

CefComponentUpdaterCToCpp::~CefComponentUpdaterCToCpp() {
  shutdown_checker::AssertNotShutdown();
}

template <>
cef_component_updater_t *
CefCToCppRefCounted<CefComponentUpdaterCToCpp, CefComponentUpdater,
                    cef_component_updater_t>::UnwrapDerived(CefWrapperType type,
                                                            CefComponentUpdater
                                                                *c) {
  CHECK(false) << __func__ << " called with unexpected class type " << type;
  return nullptr;
}

template <>
CefWrapperType
    CefCToCppRefCounted<CefComponentUpdaterCToCpp, CefComponentUpdater,
                        cef_component_updater_t>::kWrapperType =
        WT_COMPONENT_UPDATER;

#endif // CEF_API_ADDED(14600)
