// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v27.3.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#include "messages.g.h"

#include <string.h>

#include <cmath>
static guint G_GNUC_UNUSED flpigeon_hash_double(double v) {
  if (std::isnan(v)) {
    return static_cast<guint>(0x7FF80000);
  }
  if (v == 0.0) {
    v = 0.0;
  }
  union {
    double d;
    uint64_t u;
  } u;
  u.d = v;
  return static_cast<guint>(u.u ^ (u.u >> 32));
}
static gboolean G_GNUC_UNUSED flpigeon_equals_double(double a, double b) {
  return (a == b) || (std::isnan(a) && std::isnan(b));
}
static gboolean G_GNUC_UNUSED flpigeon_deep_equals(FlValue* a, FlValue* b) {
  if (a == b) {
    return TRUE;
  }
  if (a == nullptr || b == nullptr) {
    return FALSE;
  }
  if (fl_value_get_type(a) != fl_value_get_type(b)) {
    return FALSE;
  }
  switch (fl_value_get_type(a)) {
    case FL_VALUE_TYPE_NULL:
      return TRUE;
    case FL_VALUE_TYPE_BOOL:
      return fl_value_get_bool(a) == fl_value_get_bool(b);
    case FL_VALUE_TYPE_INT:
      return fl_value_get_int(a) == fl_value_get_int(b);
    case FL_VALUE_TYPE_FLOAT: {
      return flpigeon_equals_double(fl_value_get_float(a),
                                    fl_value_get_float(b));
    }
    case FL_VALUE_TYPE_STRING:
      return g_strcmp0(fl_value_get_string(a), fl_value_get_string(b)) == 0;
    case FL_VALUE_TYPE_UINT8_LIST:
      return fl_value_get_length(a) == fl_value_get_length(b) &&
             memcmp(fl_value_get_uint8_list(a), fl_value_get_uint8_list(b),
                    fl_value_get_length(a)) == 0;
    case FL_VALUE_TYPE_INT32_LIST:
      return fl_value_get_length(a) == fl_value_get_length(b) &&
             memcmp(fl_value_get_int32_list(a), fl_value_get_int32_list(b),
                    fl_value_get_length(a) * sizeof(int32_t)) == 0;
    case FL_VALUE_TYPE_INT64_LIST:
      return fl_value_get_length(a) == fl_value_get_length(b) &&
             memcmp(fl_value_get_int64_list(a), fl_value_get_int64_list(b),
                    fl_value_get_length(a) * sizeof(int64_t)) == 0;
    case FL_VALUE_TYPE_FLOAT_LIST: {
      size_t len = fl_value_get_length(a);
      if (len != fl_value_get_length(b)) {
        return FALSE;
      }
      const double* a_data = fl_value_get_float_list(a);
      const double* b_data = fl_value_get_float_list(b);
      for (size_t i = 0; i < len; i++) {
        if (!flpigeon_equals_double(a_data[i], b_data[i])) {
          return FALSE;
        }
      }
      return TRUE;
    }
    case FL_VALUE_TYPE_LIST: {
      size_t len = fl_value_get_length(a);
      if (len != fl_value_get_length(b)) {
        return FALSE;
      }
      for (size_t i = 0; i < len; i++) {
        if (!flpigeon_deep_equals(fl_value_get_list_value(a, i),
                                  fl_value_get_list_value(b, i))) {
          return FALSE;
        }
      }
      return TRUE;
    }
    case FL_VALUE_TYPE_MAP: {
      size_t len = fl_value_get_length(a);
      if (len != fl_value_get_length(b)) {
        return FALSE;
      }
      for (size_t i = 0; i < len; i++) {
        FlValue* key = fl_value_get_map_key(a, i);
        FlValue* val = fl_value_get_map_value(a, i);
        gboolean found = FALSE;
        for (size_t j = 0; j < len; j++) {
          FlValue* b_key = fl_value_get_map_key(b, j);
          if (flpigeon_deep_equals(key, b_key)) {
            FlValue* b_val = fl_value_get_map_value(b, j);
            if (flpigeon_deep_equals(val, b_val)) {
              found = TRUE;
              break;
            } else {
              return FALSE;
            }
          }
        }
        if (!found) {
          return FALSE;
        }
      }
      return TRUE;
    }
    default:
      return FALSE;
  }
  return FALSE;
}
static guint G_GNUC_UNUSED flpigeon_deep_hash(FlValue* value) {
  if (value == nullptr) {
    return 0;
  }
  switch (fl_value_get_type(value)) {
    case FL_VALUE_TYPE_NULL:
      return 0;
    case FL_VALUE_TYPE_BOOL:
      return fl_value_get_bool(value) ? 1231 : 1237;
    case FL_VALUE_TYPE_INT: {
      int64_t v = fl_value_get_int(value);
      return static_cast<guint>(v ^ (v >> 32));
    }
    case FL_VALUE_TYPE_FLOAT:
      return flpigeon_hash_double(fl_value_get_float(value));
    case FL_VALUE_TYPE_STRING:
      return g_str_hash(fl_value_get_string(value));
    case FL_VALUE_TYPE_UINT8_LIST: {
      guint result = 1;
      size_t len = fl_value_get_length(value);
      const uint8_t* data = fl_value_get_uint8_list(value);
      for (size_t i = 0; i < len; i++) {
        result = result * 31 + data[i];
      }
      return result;
    }
    case FL_VALUE_TYPE_INT32_LIST: {
      guint result = 1;
      size_t len = fl_value_get_length(value);
      const int32_t* data = fl_value_get_int32_list(value);
      for (size_t i = 0; i < len; i++) {
        result = result * 31 + static_cast<guint>(data[i]);
      }
      return result;
    }
    case FL_VALUE_TYPE_INT64_LIST: {
      guint result = 1;
      size_t len = fl_value_get_length(value);
      const int64_t* data = fl_value_get_int64_list(value);
      for (size_t i = 0; i < len; i++) {
        result = result * 31 + static_cast<guint>(data[i] ^ (data[i] >> 32));
      }
      return result;
    }
    case FL_VALUE_TYPE_FLOAT_LIST: {
      guint result = 1;
      size_t len = fl_value_get_length(value);
      const double* data = fl_value_get_float_list(value);
      for (size_t i = 0; i < len; i++) {
        result = result * 31 + flpigeon_hash_double(data[i]);
      }
      return result;
    }
    case FL_VALUE_TYPE_LIST: {
      guint result = 1;
      size_t len = fl_value_get_length(value);
      for (size_t i = 0; i < len; i++) {
        result =
            result * 31 + flpigeon_deep_hash(fl_value_get_list_value(value, i));
      }
      return result;
    }
    case FL_VALUE_TYPE_MAP: {
      guint result = 0;
      size_t len = fl_value_get_length(value);
      for (size_t i = 0; i < len; i++) {
        result += ((flpigeon_deep_hash(fl_value_get_map_key(value, i)) * 31) ^
                   flpigeon_deep_hash(fl_value_get_map_value(value, i)));
      }
      return result;
    }
    default:
      return static_cast<guint>(fl_value_get_type(value));
  }
  return 0;
}
static gchar* G_GNUC_UNUSED flpigeon_to_string(FlValue* value) {
  if (value == nullptr) {
    return g_strdup("null");
  }
  switch (fl_value_get_type(value)) {
    case FL_VALUE_TYPE_NULL:
      return g_strdup("null");
    case FL_VALUE_TYPE_BOOL:
      return g_strdup(fl_value_get_bool(value) ? "true" : "false");
    case FL_VALUE_TYPE_INT:
      return g_strdup_printf("%" G_GINT64_FORMAT, fl_value_get_int(value));
    case FL_VALUE_TYPE_FLOAT:
      return g_strdup_printf("%g", fl_value_get_float(value));
    case FL_VALUE_TYPE_STRING:
      return g_strdup_printf("\"%s\"", fl_value_get_string(value));
    case FL_VALUE_TYPE_UINT8_LIST: {
      GString* str = g_string_new("[");
      size_t len = fl_value_get_length(value);
      const uint8_t* data = fl_value_get_uint8_list(value);
      for (size_t i = 0; i < len; i++) {
        if (i > 0) {
          g_string_append(str, ", ");
        }
        g_string_append_printf(str, "%d", data[i]);
      }
      g_string_append(str, "]");
      return g_string_free(str, FALSE);
    }
    case FL_VALUE_TYPE_INT32_LIST: {
      GString* str = g_string_new("[");
      size_t len = fl_value_get_length(value);
      const int32_t* data = fl_value_get_int32_list(value);
      for (size_t i = 0; i < len; i++) {
        if (i > 0) {
          g_string_append(str, ", ");
        }
        g_string_append_printf(str, "%d", data[i]);
      }
      g_string_append(str, "]");
      return g_string_free(str, FALSE);
    }
    case FL_VALUE_TYPE_INT64_LIST: {
      GString* str = g_string_new("[");
      size_t len = fl_value_get_length(value);
      const int64_t* data = fl_value_get_int64_list(value);
      for (size_t i = 0; i < len; i++) {
        if (i > 0) {
          g_string_append(str, ", ");
        }
        g_string_append_printf(str, "%" G_GINT64_FORMAT, data[i]);
      }
      g_string_append(str, "]");
      return g_string_free(str, FALSE);
    }
    case FL_VALUE_TYPE_FLOAT_LIST: {
      GString* str = g_string_new("[");
      size_t len = fl_value_get_length(value);
      const double* data = fl_value_get_float_list(value);
      for (size_t i = 0; i < len; i++) {
        if (i > 0) {
          g_string_append(str, ", ");
        }
        g_string_append_printf(str, "%g", data[i]);
      }
      g_string_append(str, "]");
      return g_string_free(str, FALSE);
    }
    case FL_VALUE_TYPE_LIST: {
      GString* str = g_string_new("[");
      size_t len = fl_value_get_length(value);
      for (size_t i = 0; i < len; i++) {
        if (i > 0) {
          g_string_append(str, ", ");
        }
        gchar* item_str = flpigeon_to_string(fl_value_get_list_value(value, i));
        g_string_append(str, item_str);
        g_free(item_str);
      }
      g_string_append(str, "]");
      return g_string_free(str, FALSE);
    }
    case FL_VALUE_TYPE_MAP: {
      GString* str = g_string_new("{");
      size_t len = fl_value_get_length(value);
      for (size_t i = 0; i < len; i++) {
        if (i > 0) {
          g_string_append(str, ", ");
        }
        gchar* key_str = flpigeon_to_string(fl_value_get_map_key(value, i));
        gchar* val_str = flpigeon_to_string(fl_value_get_map_value(value, i));
        g_string_append_printf(str, "%s: %s", key_str, val_str);
        g_free(key_str);
        g_free(val_str);
      }
      g_string_append(str, "}");
      return g_string_free(str, FALSE);
    }
    default:
      return g_strdup("[custom]");
  }
  return g_strdup("null");
}

struct _FulMessageCodec {
  FlStandardMessageCodec parent_instance;
};

G_DEFINE_TYPE(FulMessageCodec, ful_message_codec,
              fl_standard_message_codec_get_type())

static gboolean ful_message_codec_write_value(FlStandardMessageCodec* codec,
                                              GByteArray* buffer,
                                              FlValue* value, GError** error) {
  if (fl_value_get_type(value) == FL_VALUE_TYPE_CUSTOM) {
    switch (fl_value_get_custom_type(value)) {}
  }

  return FL_STANDARD_MESSAGE_CODEC_CLASS(ful_message_codec_parent_class)
      ->write_value(codec, buffer, value, error);
}

static FlValue* ful_message_codec_read_value_of_type(
    FlStandardMessageCodec* codec, GBytes* buffer, size_t* offset, int type,
    GError** error) {
  switch (type) {
    default:
      return FL_STANDARD_MESSAGE_CODEC_CLASS(ful_message_codec_parent_class)
          ->read_value_of_type(codec, buffer, offset, type, error);
  }
}

static void ful_message_codec_init(FulMessageCodec* self) {}

static void ful_message_codec_class_init(FulMessageCodecClass* klass) {
  FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->write_value =
      ful_message_codec_write_value;
  FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->read_value_of_type =
      ful_message_codec_read_value_of_type;
}

static FulMessageCodec* ful_message_codec_new() {
  FulMessageCodec* self =
      FUL_MESSAGE_CODEC(g_object_new(ful_message_codec_get_type(), nullptr));
  return self;
}

struct _FulUrlLauncherApiCanLaunchUrlResponse {
  GObject parent_instance;

  FlValue* value;
};

G_DEFINE_TYPE(FulUrlLauncherApiCanLaunchUrlResponse,
              ful_url_launcher_api_can_launch_url_response, G_TYPE_OBJECT)

static void ful_url_launcher_api_can_launch_url_response_dispose(
    GObject* object) {
  FulUrlLauncherApiCanLaunchUrlResponse* self =
      FUL_URL_LAUNCHER_API_CAN_LAUNCH_URL_RESPONSE(object);
  g_clear_pointer(&self->value, fl_value_unref);
  G_OBJECT_CLASS(ful_url_launcher_api_can_launch_url_response_parent_class)
      ->dispose(object);
}

static void ful_url_launcher_api_can_launch_url_response_init(
    FulUrlLauncherApiCanLaunchUrlResponse* self) {}

static void ful_url_launcher_api_can_launch_url_response_class_init(
    FulUrlLauncherApiCanLaunchUrlResponseClass* klass) {
  G_OBJECT_CLASS(klass)->dispose =
      ful_url_launcher_api_can_launch_url_response_dispose;
}

FulUrlLauncherApiCanLaunchUrlResponse*
ful_url_launcher_api_can_launch_url_response_new(gboolean return_value) {
  FulUrlLauncherApiCanLaunchUrlResponse* self =
      FUL_URL_LAUNCHER_API_CAN_LAUNCH_URL_RESPONSE(g_object_new(
          ful_url_launcher_api_can_launch_url_response_get_type(), nullptr));
  self->value = fl_value_new_list();
  fl_value_append_take(self->value, fl_value_new_bool(return_value));
  return self;
}

FulUrlLauncherApiCanLaunchUrlResponse*
ful_url_launcher_api_can_launch_url_response_new_error(const gchar* code,
                                                       const gchar* message,
                                                       FlValue* details) {
  FulUrlLauncherApiCanLaunchUrlResponse* self =
      FUL_URL_LAUNCHER_API_CAN_LAUNCH_URL_RESPONSE(g_object_new(
          ful_url_launcher_api_can_launch_url_response_get_type(), nullptr));
  self->value = fl_value_new_list();
  fl_value_append_take(self->value, fl_value_new_string(code));
  fl_value_append_take(self->value,
                       fl_value_new_string(message != nullptr ? message : ""));
  fl_value_append_take(self->value, details != nullptr ? fl_value_ref(details)
                                                       : fl_value_new_null());
  return self;
}

struct _FulUrlLauncherApiLaunchUrlResponse {
  GObject parent_instance;

  FlValue* value;
};

G_DEFINE_TYPE(FulUrlLauncherApiLaunchUrlResponse,
              ful_url_launcher_api_launch_url_response, G_TYPE_OBJECT)

static void ful_url_launcher_api_launch_url_response_dispose(GObject* object) {
  FulUrlLauncherApiLaunchUrlResponse* self =
      FUL_URL_LAUNCHER_API_LAUNCH_URL_RESPONSE(object);
  g_clear_pointer(&self->value, fl_value_unref);
  G_OBJECT_CLASS(ful_url_launcher_api_launch_url_response_parent_class)
      ->dispose(object);
}

static void ful_url_launcher_api_launch_url_response_init(
    FulUrlLauncherApiLaunchUrlResponse* self) {}

static void ful_url_launcher_api_launch_url_response_class_init(
    FulUrlLauncherApiLaunchUrlResponseClass* klass) {
  G_OBJECT_CLASS(klass)->dispose =
      ful_url_launcher_api_launch_url_response_dispose;
}

FulUrlLauncherApiLaunchUrlResponse*
ful_url_launcher_api_launch_url_response_new(const gchar* return_value) {
  FulUrlLauncherApiLaunchUrlResponse* self =
      FUL_URL_LAUNCHER_API_LAUNCH_URL_RESPONSE(g_object_new(
          ful_url_launcher_api_launch_url_response_get_type(), nullptr));
  self->value = fl_value_new_list();
  fl_value_append_take(self->value, return_value != nullptr
                                        ? fl_value_new_string(return_value)
                                        : fl_value_new_null());
  return self;
}

FulUrlLauncherApiLaunchUrlResponse*
ful_url_launcher_api_launch_url_response_new_error(const gchar* code,
                                                   const gchar* message,
                                                   FlValue* details) {
  FulUrlLauncherApiLaunchUrlResponse* self =
      FUL_URL_LAUNCHER_API_LAUNCH_URL_RESPONSE(g_object_new(
          ful_url_launcher_api_launch_url_response_get_type(), nullptr));
  self->value = fl_value_new_list();
  fl_value_append_take(self->value, fl_value_new_string(code));
  fl_value_append_take(self->value,
                       fl_value_new_string(message != nullptr ? message : ""));
  fl_value_append_take(self->value, details != nullptr ? fl_value_ref(details)
                                                       : fl_value_new_null());
  return self;
}

struct _FulUrlLauncherApi {
  GObject parent_instance;

  const FulUrlLauncherApiVTable* vtable;
  gpointer user_data;
  GDestroyNotify user_data_free_func;
};

G_DEFINE_TYPE(FulUrlLauncherApi, ful_url_launcher_api, G_TYPE_OBJECT)

static void ful_url_launcher_api_dispose(GObject* object) {
  FulUrlLauncherApi* self = FUL_URL_LAUNCHER_API(object);
  if (self->user_data != nullptr) {
    self->user_data_free_func(self->user_data);
  }
  self->user_data = nullptr;
  G_OBJECT_CLASS(ful_url_launcher_api_parent_class)->dispose(object);
}

static void ful_url_launcher_api_init(FulUrlLauncherApi* self) {}

static void ful_url_launcher_api_class_init(FulUrlLauncherApiClass* klass) {
  G_OBJECT_CLASS(klass)->dispose = ful_url_launcher_api_dispose;
}

static FulUrlLauncherApi* ful_url_launcher_api_new(
    const FulUrlLauncherApiVTable* vtable, gpointer user_data,
    GDestroyNotify user_data_free_func) {
  FulUrlLauncherApi* self = FUL_URL_LAUNCHER_API(
      g_object_new(ful_url_launcher_api_get_type(), nullptr));
  self->vtable = vtable;
  self->user_data = user_data;
  self->user_data_free_func = user_data_free_func;
  return self;
}

static void ful_url_launcher_api_can_launch_url_cb(
    FlBasicMessageChannel* channel, FlValue* message_,
    FlBasicMessageChannelResponseHandle* response_handle, gpointer user_data) {
  FulUrlLauncherApi* self = FUL_URL_LAUNCHER_API(user_data);

  if (self->vtable == nullptr || self->vtable->can_launch_url == nullptr) {
    return;
  }

  FlValue* value0 = fl_value_get_list_value(message_, 0);
  const gchar* url = fl_value_get_string(value0);
  g_autoptr(FulUrlLauncherApiCanLaunchUrlResponse) response =
      self->vtable->can_launch_url(url, self->user_data);
  if (response == nullptr) {
    g_warning("No response returned to %s.%s", "UrlLauncherApi",
              "canLaunchUrl");
    return;
  }

  g_autoptr(GError) error = NULL;
  if (!fl_basic_message_channel_respond(channel, response_handle,
                                        response->value, &error)) {
    g_warning("Failed to send response to %s.%s: %s", "UrlLauncherApi",
              "canLaunchUrl", error->message);
  }
}

static void ful_url_launcher_api_launch_url_cb(
    FlBasicMessageChannel* channel, FlValue* message_,
    FlBasicMessageChannelResponseHandle* response_handle, gpointer user_data) {
  FulUrlLauncherApi* self = FUL_URL_LAUNCHER_API(user_data);

  if (self->vtable == nullptr || self->vtable->launch_url == nullptr) {
    return;
  }

  FlValue* value0 = fl_value_get_list_value(message_, 0);
  const gchar* url = fl_value_get_string(value0);
  g_autoptr(FulUrlLauncherApiLaunchUrlResponse) response =
      self->vtable->launch_url(url, self->user_data);
  if (response == nullptr) {
    g_warning("No response returned to %s.%s", "UrlLauncherApi", "launchUrl");
    return;
  }

  g_autoptr(GError) error = NULL;
  if (!fl_basic_message_channel_respond(channel, response_handle,
                                        response->value, &error)) {
    g_warning("Failed to send response to %s.%s: %s", "UrlLauncherApi",
              "launchUrl", error->message);
  }
}

void ful_url_launcher_api_set_method_handlers(
    FlBinaryMessenger* messenger, const gchar* suffix,
    const FulUrlLauncherApiVTable* vtable, gpointer user_data,
    GDestroyNotify user_data_free_func) {
  g_autofree gchar* dot_suffix =
      suffix != nullptr ? g_strdup_printf(".%s", suffix) : g_strdup("");
  g_autoptr(FulUrlLauncherApi) api_data =
      ful_url_launcher_api_new(vtable, user_data, user_data_free_func);

  g_autoptr(FulMessageCodec) codec = ful_message_codec_new();
  g_autofree gchar* can_launch_url_channel_name = g_strdup_printf(
      "dev.flutter.pigeon.url_launcher_linux.UrlLauncherApi.canLaunchUrl%s",
      dot_suffix);
  g_autoptr(FlBasicMessageChannel) can_launch_url_channel =
      fl_basic_message_channel_new(messenger, can_launch_url_channel_name,
                                   FL_MESSAGE_CODEC(codec));
  fl_basic_message_channel_set_message_handler(
      can_launch_url_channel, ful_url_launcher_api_can_launch_url_cb,
      g_object_ref(api_data), g_object_unref);
  g_autofree gchar* launch_url_channel_name = g_strdup_printf(
      "dev.flutter.pigeon.url_launcher_linux.UrlLauncherApi.launchUrl%s",
      dot_suffix);
  g_autoptr(FlBasicMessageChannel) launch_url_channel =
      fl_basic_message_channel_new(messenger, launch_url_channel_name,
                                   FL_MESSAGE_CODEC(codec));
  fl_basic_message_channel_set_message_handler(
      launch_url_channel, ful_url_launcher_api_launch_url_cb,
      g_object_ref(api_data), g_object_unref);
}

void ful_url_launcher_api_clear_method_handlers(FlBinaryMessenger* messenger,
                                                const gchar* suffix) {
  g_autofree gchar* dot_suffix =
      suffix != nullptr ? g_strdup_printf(".%s", suffix) : g_strdup("");

  g_autoptr(FulMessageCodec) codec = ful_message_codec_new();
  g_autofree gchar* can_launch_url_channel_name = g_strdup_printf(
      "dev.flutter.pigeon.url_launcher_linux.UrlLauncherApi.canLaunchUrl%s",
      dot_suffix);
  g_autoptr(FlBasicMessageChannel) can_launch_url_channel =
      fl_basic_message_channel_new(messenger, can_launch_url_channel_name,
                                   FL_MESSAGE_CODEC(codec));
  fl_basic_message_channel_set_message_handler(can_launch_url_channel, nullptr,
                                               nullptr, nullptr);
  g_autofree gchar* launch_url_channel_name = g_strdup_printf(
      "dev.flutter.pigeon.url_launcher_linux.UrlLauncherApi.launchUrl%s",
      dot_suffix);
  g_autoptr(FlBasicMessageChannel) launch_url_channel =
      fl_basic_message_channel_new(messenger, launch_url_channel_name,
                                   FL_MESSAGE_CODEC(codec));
  fl_basic_message_channel_set_message_handler(launch_url_channel, nullptr,
                                               nullptr, nullptr);
}
