/* github-release-source.c generated by valac 0.56.19, the Vala compiler
 * generated from github-release-source.vala, do not modify */

#include "protonplus_core.h"
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	PROTON_PLUS_PROVIDERS_SOURCES_GIT_HUB_RELEASE_SOURCE_0_PROPERTY,
	PROTON_PLUS_PROVIDERS_SOURCES_GIT_HUB_RELEASE_SOURCE_NUM_PROPERTIES
};
static GParamSpec* proton_plus_providers_sources_git_hub_release_source_properties[PROTON_PLUS_PROVIDERS_SOURCES_GIT_HUB_RELEASE_SOURCE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData;

struct _ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ProtonPlusProvidersSourcesGitHubReleaseSource* self;
	ProtonPlusModelsProvidersProviderDefinition* definition;
	gint requested_page;
	gint limit;
	ProtonPlusModelsToolsReleasePageResult* result;
	ProtonPlusUtilsWebResponse* response;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	ProtonPlusUtilsWebResponse* _tmp4_;
	ProtonPlusUtilsWebResponse* _tmp5_;
	ProtonPlusUtilsWebResponse* _tmp6_;
	ProtonPlusReturnCode _tmp7_;
	ProtonPlusReturnCode _tmp8_;
	ProtonPlusUtilsWebResponse* _tmp9_;
	ProtonPlusReturnCode _tmp10_;
	ProtonPlusReturnCode _tmp11_;
	ProtonPlusModelsToolsReleasePageResult* _tmp12_;
	ProtonPlusUtilsWebResponse* _tmp13_;
	const gchar* _tmp14_;
	const gchar* _tmp15_;
	ProtonPlusModelsToolsReleasePageResult* _tmp16_;
};

static gpointer proton_plus_providers_sources_git_hub_release_source_parent_class = NULL;
static ProtonPlusProvidersSourcesReleaseSourceIface * proton_plus_providers_sources_git_hub_release_source_proton_plus_providers_sources_release_source_parent_iface = NULL;

static void proton_plus_providers_sources_git_hub_release_source_real_fetch_page_data_free (gpointer _data);
static void proton_plus_providers_sources_git_hub_release_source_real_fetch_page (ProtonPlusProvidersSourcesReleaseSource* base,
                                                                           ProtonPlusModelsProvidersProviderDefinition* definition,
                                                                           gint requested_page,
                                                                           gint limit,
                                                                           GAsyncReadyCallback _callback_,
                                                                           gpointer _user_data_);
static gboolean proton_plus_providers_sources_git_hub_release_source_real_fetch_page_co (ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData* _data_);
static void proton_plus_providers_sources_git_hub_release_source_fetch_page_ready (GObject* source_object,
                                                                            GAsyncResult* _res_,
                                                                            gpointer _user_data_);
VALA_EXTERN ProtonPlusModelsToolsReleasePageResult* proton_plus_providers_sources_git_hub_compatible_release_parser_parse (ProtonPlusModelsProvidersProviderDefinition* definition,
                                                                                                               const gchar* response_body,
                                                                                                               gint requested_page,
                                                                                                               gint limit);
static GType proton_plus_providers_sources_git_hub_release_source_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static void
proton_plus_providers_sources_git_hub_release_source_real_fetch_page_data_free (gpointer _data)
{
	ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->definition);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData, _data_);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
proton_plus_providers_sources_git_hub_release_source_real_fetch_page (ProtonPlusProvidersSourcesReleaseSource* base,
                                                                      ProtonPlusModelsProvidersProviderDefinition* definition,
                                                                      gint requested_page,
                                                                      gint limit,
                                                                      GAsyncReadyCallback _callback_,
                                                                      gpointer _user_data_)
{
	ProtonPlusProvidersSourcesGitHubReleaseSource * self;
	ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData* _data_;
	ProtonPlusProvidersSourcesGitHubReleaseSource* _tmp0_;
	ProtonPlusModelsProvidersProviderDefinition* _tmp1_;
	g_return_if_fail (definition != NULL);
	self = (ProtonPlusProvidersSourcesGitHubReleaseSource*) base;
	_data_ = g_slice_new0 (ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_providers_sources_git_hub_release_source_real_fetch_page_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (definition);
	_g_object_unref0 (_data_->definition);
	_data_->definition = _tmp1_;
	_data_->requested_page = requested_page;
	_data_->limit = limit;
	proton_plus_providers_sources_git_hub_release_source_real_fetch_page_co (_data_);
}

static ProtonPlusModelsToolsReleasePageResult*
proton_plus_providers_sources_git_hub_release_source_fetch_page_finish (ProtonPlusProvidersSourcesReleaseSource* base,
                                                                        GAsyncResult* _res_)
{
	ProtonPlusModelsToolsReleasePageResult* result;
	ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
proton_plus_providers_sources_git_hub_release_source_fetch_page_ready (GObject* source_object,
                                                                       GAsyncResult* _res_,
                                                                       gpointer _user_data_)
{
	ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_providers_sources_git_hub_release_source_real_fetch_page_co (_data_);
}

static gboolean
proton_plus_providers_sources_git_hub_release_source_real_fetch_page_co (ProtonPlusProvidersSourcesGitHubReleaseSourceFetchPageData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = proton_plus_models_providers_provider_definition_get_endpoint (_data_->definition);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = g_strdup_printf ("%s?per_page=%i&page=%i", _data_->_tmp1_, _data_->limit, _data_->requested_page);
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_state_ = 1;
	proton_plus_utils_web_get_request (_data_->_tmp3_, PROTON_PLUS_UTILS_WEB_GET_REQUEST_TYPE_GITHUB, NULL, proton_plus_providers_sources_git_hub_release_source_fetch_page_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp4_ = proton_plus_utils_web_get_request_finish (_data_->_res_);
	_data_->_tmp5_ = _data_->_tmp4_;
	_g_free0 (_data_->_tmp3_);
	_data_->response = _data_->_tmp5_;
	_data_->_tmp6_ = _data_->response;
	_data_->_tmp7_ = proton_plus_utils_web_response_get_code (_data_->_tmp6_);
	_data_->_tmp8_ = _data_->_tmp7_;
	if (_data_->_tmp8_ != PROTON_PLUS_RETURN_CODE_VALID_REQUEST) {
		_data_->_tmp9_ = _data_->response;
		_data_->_tmp10_ = proton_plus_utils_web_response_get_code (_data_->_tmp9_);
		_data_->_tmp11_ = _data_->_tmp10_;
		_data_->_tmp12_ = proton_plus_models_tools_release_page_result_failure (_data_->_tmp11_);
		_data_->result = _data_->_tmp12_;
		_g_object_unref0 (_data_->response);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp13_ = _data_->response;
	_data_->_tmp14_ = proton_plus_utils_web_response_get_body (_data_->_tmp13_);
	_data_->_tmp15_ = _data_->_tmp14_;
	_data_->_tmp16_ = proton_plus_providers_sources_git_hub_release_source_parse_response (_data_->self, _data_->definition, _data_->_tmp15_, _data_->requested_page, _data_->limit);
	_data_->result = _data_->_tmp16_;
	_g_object_unref0 (_data_->response);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

ProtonPlusModelsToolsReleasePageResult*
proton_plus_providers_sources_git_hub_release_source_parse_response (ProtonPlusProvidersSourcesGitHubReleaseSource* self,
                                                                     ProtonPlusModelsProvidersProviderDefinition* definition,
                                                                     const gchar* response_body,
                                                                     gint requested_page,
                                                                     gint limit)
{
	ProtonPlusModelsToolsReleasePageResult* _tmp0_;
	ProtonPlusModelsToolsReleasePageResult* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (definition != NULL, NULL);
	g_return_val_if_fail (response_body != NULL, NULL);
	_tmp0_ = proton_plus_providers_sources_git_hub_compatible_release_parser_parse (definition, response_body, requested_page, limit);
	result = _tmp0_;
	return result;
}

ProtonPlusProvidersSourcesGitHubReleaseSource*
proton_plus_providers_sources_git_hub_release_source_construct (GType object_type)
{
	ProtonPlusProvidersSourcesGitHubReleaseSource * self = NULL;
	self = (ProtonPlusProvidersSourcesGitHubReleaseSource*) g_object_new (object_type, NULL);
	return self;
}

ProtonPlusProvidersSourcesGitHubReleaseSource*
proton_plus_providers_sources_git_hub_release_source_new (void)
{
	return proton_plus_providers_sources_git_hub_release_source_construct (PROTON_PLUS_PROVIDERS_SOURCES_TYPE_GIT_HUB_RELEASE_SOURCE);
}

static void
proton_plus_providers_sources_git_hub_release_source_class_init (ProtonPlusProvidersSourcesGitHubReleaseSourceClass * klass,
                                                                 gpointer klass_data)
{
	proton_plus_providers_sources_git_hub_release_source_parent_class = g_type_class_peek_parent (klass);
}

static void
proton_plus_providers_sources_git_hub_release_source_proton_plus_providers_sources_release_source_interface_init (ProtonPlusProvidersSourcesReleaseSourceIface * iface,
                                                                                                                  gpointer iface_data)
{
	proton_plus_providers_sources_git_hub_release_source_proton_plus_providers_sources_release_source_parent_iface = g_type_interface_peek_parent (iface);
	iface->fetch_page = (void (*) (ProtonPlusProvidersSourcesReleaseSource*, ProtonPlusModelsProvidersProviderDefinition*, gint, gint, GAsyncReadyCallback, gpointer)) proton_plus_providers_sources_git_hub_release_source_real_fetch_page;
	iface->fetch_page_finish = (ProtonPlusModelsToolsReleasePageResult* (*) (ProtonPlusProvidersSourcesReleaseSource*, GAsyncResult*)) proton_plus_providers_sources_git_hub_release_source_fetch_page_finish;
}

static void
proton_plus_providers_sources_git_hub_release_source_instance_init (ProtonPlusProvidersSourcesGitHubReleaseSource * self,
                                                                    gpointer klass)
{
}

static GType
proton_plus_providers_sources_git_hub_release_source_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusProvidersSourcesGitHubReleaseSourceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_providers_sources_git_hub_release_source_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusProvidersSourcesGitHubReleaseSource), 0, (GInstanceInitFunc) proton_plus_providers_sources_git_hub_release_source_instance_init, NULL };
	static const GInterfaceInfo proton_plus_providers_sources_release_source_info = { (GInterfaceInitFunc) proton_plus_providers_sources_git_hub_release_source_proton_plus_providers_sources_release_source_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType proton_plus_providers_sources_git_hub_release_source_type_id;
	proton_plus_providers_sources_git_hub_release_source_type_id = g_type_register_static (G_TYPE_OBJECT, "ProtonPlusProvidersSourcesGitHubReleaseSource", &g_define_type_info, 0);
	g_type_add_interface_static (proton_plus_providers_sources_git_hub_release_source_type_id, PROTON_PLUS_PROVIDERS_SOURCES_TYPE_RELEASE_SOURCE, &proton_plus_providers_sources_release_source_info);
	return proton_plus_providers_sources_git_hub_release_source_type_id;
}

GType
proton_plus_providers_sources_git_hub_release_source_get_type (void)
{
	static volatile gsize proton_plus_providers_sources_git_hub_release_source_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_providers_sources_git_hub_release_source_type_id__once)) {
		GType proton_plus_providers_sources_git_hub_release_source_type_id;
		proton_plus_providers_sources_git_hub_release_source_type_id = proton_plus_providers_sources_git_hub_release_source_get_type_once ();
		g_once_init_leave (&proton_plus_providers_sources_git_hub_release_source_type_id__once, proton_plus_providers_sources_git_hub_release_source_type_id);
	}
	return proton_plus_providers_sources_git_hub_release_source_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

