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

#include "protonplus_core.h"
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <json-glib/json-glib.h>
#include <gee.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_LAB_RELEASE_SOURCE_0_PROPERTY,
	PROTON_PLUS_PROVIDERS_SOURCES_GIT_LAB_RELEASE_SOURCE_NUM_PROPERTIES
};
static GParamSpec* proton_plus_providers_sources_git_lab_release_source_properties[PROTON_PLUS_PROVIDERS_SOURCES_GIT_LAB_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 _ProtonPlusProvidersSourcesGitLabReleaseSourceFetchPageData ProtonPlusProvidersSourcesGitLabReleaseSourceFetchPageData;
#define _json_array_unref0(var) ((var == NULL) ? NULL : (var = (json_array_unref (var), NULL)))
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))

struct _ProtonPlusProvidersSourcesGitLabReleaseSourceFetchPageData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ProtonPlusProvidersSourcesGitLabReleaseSource* 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_lab_release_source_parent_class = NULL;
static ProtonPlusProvidersSourcesReleaseSourceIface * proton_plus_providers_sources_git_lab_release_source_proton_plus_providers_sources_release_source_parent_iface = NULL;

static void proton_plus_providers_sources_git_lab_release_source_real_fetch_page_data_free (gpointer _data);
static void proton_plus_providers_sources_git_lab_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_lab_release_source_real_fetch_page_co (ProtonPlusProvidersSourcesGitLabReleaseSourceFetchPageData* _data_);
static void proton_plus_providers_sources_git_lab_release_source_fetch_page_ready (GObject* source_object,
                                                                            GAsyncResult* _res_,
                                                                            gpointer _user_data_);
VALA_EXTERN JsonArray* proton_plus_providers_sources_release_source_support_parse_array (const gchar* response_body);
static GeeLinkedList* proton_plus_providers_sources_git_lab_release_source_parse_assets (ProtonPlusProvidersSourcesGitLabReleaseSource* self,
                                                                                  JsonObject* release);
VALA_EXTERN gchar* proton_plus_providers_sources_release_source_support_get_iso8601_date (JsonObject* object,
                                                                              const gchar* member);
VALA_EXTERN void proton_plus_providers_sources_release_source_support_add_variants (ProtonPlusModelsRelease* release,
                                                                        GeeIterable* variants);
static GType proton_plus_providers_sources_git_lab_release_source_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

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

static void
proton_plus_providers_sources_git_lab_release_source_real_fetch_page (ProtonPlusProvidersSourcesReleaseSource* base,
                                                                      ProtonPlusModelsProvidersProviderDefinition* definition,
                                                                      gint requested_page,
                                                                      gint limit,
                                                                      GAsyncReadyCallback _callback_,
                                                                      gpointer _user_data_)
{
	ProtonPlusProvidersSourcesGitLabReleaseSource * self;
	ProtonPlusProvidersSourcesGitLabReleaseSourceFetchPageData* _data_;
	ProtonPlusProvidersSourcesGitLabReleaseSource* _tmp0_;
	ProtonPlusModelsProvidersProviderDefinition* _tmp1_;
	g_return_if_fail (definition != NULL);
	self = (ProtonPlusProvidersSourcesGitLabReleaseSource*) base;
	_data_ = g_slice_new0 (ProtonPlusProvidersSourcesGitLabReleaseSourceFetchPageData);
	_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_lab_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_lab_release_source_real_fetch_page_co (_data_);
}

static ProtonPlusModelsToolsReleasePageResult*
proton_plus_providers_sources_git_lab_release_source_fetch_page_finish (ProtonPlusProvidersSourcesReleaseSource* base,
                                                                        GAsyncResult* _res_)
{
	ProtonPlusModelsToolsReleasePageResult* result;
	ProtonPlusProvidersSourcesGitLabReleaseSourceFetchPageData* _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_lab_release_source_fetch_page_ready (GObject* source_object,
                                                                       GAsyncResult* _res_,
                                                                       gpointer _user_data_)
{
	ProtonPlusProvidersSourcesGitLabReleaseSourceFetchPageData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_providers_sources_git_lab_release_source_real_fetch_page_co (_data_);
}

static gboolean
proton_plus_providers_sources_git_lab_release_source_real_fetch_page_co (ProtonPlusProvidersSourcesGitLabReleaseSourceFetchPageData* _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_GITLAB, NULL, proton_plus_providers_sources_git_lab_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_lab_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;
}

static gpointer
_json_object_ref0 (gpointer self)
{
	return self ? json_object_ref (self) : NULL;
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

ProtonPlusModelsToolsReleasePageResult*
proton_plus_providers_sources_git_lab_release_source_parse_response (ProtonPlusProvidersSourcesGitLabReleaseSource* self,
                                                                     ProtonPlusModelsProvidersProviderDefinition* definition,
                                                                     const gchar* response_body,
                                                                     gint requested_page,
                                                                     gint limit)
{
	JsonArray* root_array = NULL;
	JsonArray* _tmp0_;
	JsonArray* _tmp1_;
	GeeLinkedList* releases = NULL;
	GeeLinkedList* _tmp3_;
	GeeLinkedList* _tmp61_;
	JsonArray* _tmp62_;
	ProtonPlusModelsToolsReleasePage* _tmp63_;
	ProtonPlusModelsToolsReleasePage* _tmp64_;
	ProtonPlusModelsToolsReleasePageResult* _tmp65_;
	ProtonPlusModelsToolsReleasePageResult* _tmp66_;
	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_release_source_support_parse_array (response_body);
	root_array = _tmp0_;
	_tmp1_ = root_array;
	if (_tmp1_ == NULL) {
		ProtonPlusModelsToolsReleasePageResult* _tmp2_;
		_tmp2_ = proton_plus_models_tools_release_page_result_failure (PROTON_PLUS_RETURN_CODE_INVALID_DATA);
		result = _tmp2_;
		_json_array_unref0 (root_array);
		return result;
	}
	_tmp3_ = gee_linked_list_new (PROTON_PLUS_MODELS_TYPE_RELEASE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	releases = _tmp3_;
	{
		gint index = 0;
		index = 0;
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				JsonArray* _tmp6_;
				JsonObject* object = NULL;
				JsonArray* _tmp7_;
				JsonObject* _tmp8_;
				JsonObject* _tmp9_;
				JsonObject* _tmp10_;
				gchar* tag_name = NULL;
				JsonObject* _tmp11_;
				const gchar* _tmp12_;
				gchar* _tmp13_;
				const gchar* _tmp14_;
				GeeLinkedList* assets = NULL;
				JsonObject* _tmp15_;
				GeeLinkedList* _tmp16_;
				GeeLinkedList* _tmp17_;
				gint _tmp18_;
				gint _tmp19_;
				GeeLinkedList* variants = NULL;
				const gchar* _tmp20_;
				const gchar* _tmp21_;
				GeeLinkedList* _tmp22_;
				GeeLinkedList* _tmp23_;
				ProtonPlusModelsAssetsAsset* primary_asset = NULL;
				GeeLinkedList* _tmp24_;
				GeeLinkedList* _tmp25_;
				ProtonPlusModelsAssetsAsset* _tmp26_;
				ProtonPlusModelsAssetsAsset* _tmp27_;
				JsonObject* links = NULL;
				JsonObject* _tmp28_;
				JsonObject* _tmp29_;
				JsonObject* _tmp30_;
				const gchar* _tmp31_ = NULL;
				JsonObject* _tmp32_;
				gchar* _tmp35_ = NULL;
				gboolean _tmp36_ = FALSE;
				JsonObject* _tmp37_;
				ProtonPlusModelsRelease* release = NULL;
				const gchar* _tmp42_;
				JsonObject* _tmp43_;
				const gchar* _tmp44_;
				gchar* _tmp45_;
				gchar* _tmp46_;
				JsonObject* _tmp47_;
				gchar* _tmp48_;
				gchar* _tmp49_;
				ProtonPlusModelsAssetsAsset* _tmp50_;
				ProtonPlusModelsAssetsAsset* _tmp51_;
				gint64 _tmp52_;
				gint64 _tmp53_;
				const gchar* _tmp54_;
				ProtonPlusModelsRelease* _tmp55_;
				ProtonPlusModelsRelease* _tmp56_;
				ProtonPlusModelsRelease* _tmp57_;
				GeeLinkedList* _tmp58_;
				GeeLinkedList* _tmp59_;
				ProtonPlusModelsRelease* _tmp60_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = index;
					index = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				_tmp6_ = root_array;
				if (!(((guint) index) < json_array_get_length (_tmp6_))) {
					break;
				}
				_tmp7_ = root_array;
				_tmp8_ = json_array_get_object_element (_tmp7_, (guint) index);
				_tmp9_ = _json_object_ref0 (_tmp8_);
				object = _tmp9_;
				_tmp10_ = object;
				if (_tmp10_ == NULL) {
					_json_object_unref0 (object);
					continue;
				}
				_tmp11_ = object;
				_tmp12_ = json_object_get_string_member_with_default (_tmp11_, "tag_name", "");
				_tmp13_ = g_strdup (_tmp12_);
				tag_name = _tmp13_;
				_tmp14_ = tag_name;
				if (!proton_plus_providers_sources_catalog_release_builder_is_eligible (definition, _tmp14_)) {
					_g_free0 (tag_name);
					_json_object_unref0 (object);
					continue;
				}
				_tmp15_ = object;
				_tmp16_ = proton_plus_providers_sources_git_lab_release_source_parse_assets (self, _tmp15_);
				assets = _tmp16_;
				_tmp17_ = assets;
				_tmp18_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp17_);
				_tmp19_ = _tmp18_;
				if (_tmp19_ == 0) {
					_g_object_unref0 (assets);
					_g_free0 (tag_name);
					_json_object_unref0 (object);
					continue;
				}
				_tmp20_ = tag_name;
				_tmp21_ = tag_name;
				_tmp22_ = assets;
				_tmp23_ = proton_plus_providers_sources_catalog_release_builder_create_variants (definition, _tmp20_, _tmp21_, _tmp22_);
				variants = _tmp23_;
				_tmp24_ = assets;
				_tmp25_ = variants;
				_tmp26_ = proton_plus_providers_sources_catalog_release_builder_select_default_asset (_tmp24_, _tmp25_);
				primary_asset = _tmp26_;
				_tmp27_ = primary_asset;
				if (_tmp27_ == NULL) {
					_g_object_unref0 (primary_asset);
					_g_object_unref0 (variants);
					_g_object_unref0 (assets);
					_g_free0 (tag_name);
					_json_object_unref0 (object);
					continue;
				}
				_tmp28_ = object;
				_tmp29_ = json_object_get_object_member (_tmp28_, "_links");
				_tmp30_ = _json_object_ref0 (_tmp29_);
				links = _tmp30_;
				_tmp32_ = links;
				if (_tmp32_ != NULL) {
					JsonObject* _tmp33_;
					const gchar* _tmp34_;
					_tmp33_ = links;
					_tmp34_ = json_object_get_string_member_with_default (_tmp33_, "self", "");
					_tmp31_ = _tmp34_;
				} else {
					_tmp31_ = "";
				}
				_tmp37_ = object;
				if (json_object_has_member (_tmp37_, "id")) {
					JsonObject* _tmp38_;
					_tmp38_ = object;
					_tmp36_ = json_object_get_int_member (_tmp38_, "id") > ((gint64) 0);
				} else {
					_tmp36_ = FALSE;
				}
				if (_tmp36_) {
					JsonObject* _tmp39_;
					gchar* _tmp40_;
					_tmp39_ = object;
					_tmp40_ = g_strdup_printf ("%" G_GINT64_FORMAT, json_object_get_int_member (_tmp39_, "id"));
					_g_free0 (_tmp35_);
					_tmp35_ = _tmp40_;
				} else {
					gchar* _tmp41_;
					_tmp41_ = g_strdup ("");
					_g_free0 (_tmp35_);
					_tmp35_ = _tmp41_;
				}
				_tmp42_ = tag_name;
				_tmp43_ = object;
				_tmp44_ = json_object_get_string_member_with_default (_tmp43_, "description", "");
				_tmp45_ = string_strip (_tmp44_);
				_tmp46_ = _tmp45_;
				_tmp47_ = object;
				_tmp48_ = proton_plus_providers_sources_release_source_support_get_iso8601_date (_tmp47_, "created_at");
				_tmp49_ = _tmp48_;
				_tmp50_ = primary_asset;
				_tmp51_ = primary_asset;
				_tmp52_ = proton_plus_models_assets_asset_get_download_size (_tmp51_);
				_tmp53_ = _tmp52_;
				_tmp54_ = tag_name;
				_tmp55_ = proton_plus_models_release_new (_tmp42_, _tmp46_, _tmp49_, _tmp50_, _tmp31_, &_tmp53_, _tmp35_, _tmp54_, PROTON_PLUS_MODELS_RELEASE_KIND_GENERIC, "");
				_tmp56_ = _tmp55_;
				_g_free0 (_tmp49_);
				_g_free0 (_tmp46_);
				release = _tmp56_;
				_tmp57_ = release;
				_tmp58_ = variants;
				proton_plus_providers_sources_release_source_support_add_variants (_tmp57_, (GeeIterable*) _tmp58_);
				_tmp59_ = releases;
				_tmp60_ = release;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp59_, _tmp60_);
				_g_object_unref0 (release);
				_g_free0 (_tmp35_);
				_json_object_unref0 (links);
				_g_object_unref0 (primary_asset);
				_g_object_unref0 (variants);
				_g_object_unref0 (assets);
				_g_free0 (tag_name);
				_json_object_unref0 (object);
			}
		}
	}
	_tmp61_ = releases;
	_tmp62_ = root_array;
	_tmp63_ = proton_plus_models_tools_release_page_new (_tmp61_, requested_page + 1, json_array_get_length (_tmp62_) == ((guint) limit));
	_tmp64_ = _tmp63_;
	_tmp65_ = proton_plus_models_tools_release_page_result_success (_tmp64_);
	_tmp66_ = _tmp65_;
	_g_object_unref0 (_tmp64_);
	result = _tmp66_;
	_g_object_unref0 (releases);
	_json_array_unref0 (root_array);
	return result;
}

static gpointer
_json_array_ref0 (gpointer self)
{
	return self ? json_array_ref (self) : NULL;
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

static GeeLinkedList*
proton_plus_providers_sources_git_lab_release_source_parse_assets (ProtonPlusProvidersSourcesGitLabReleaseSource* self,
                                                                   JsonObject* release)
{
	GeeLinkedList* assets = NULL;
	GeeLinkedList* _tmp0_;
	JsonObject* container = NULL;
	JsonObject* _tmp1_;
	JsonObject* _tmp2_;
	JsonArray* _tmp3_ = NULL;
	JsonObject* _tmp4_;
	JsonArray* array = NULL;
	JsonArray* _tmp7_;
	JsonArray* _tmp8_;
	GeeLinkedList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (release != NULL, NULL);
	_tmp0_ = gee_linked_list_new (PROTON_PLUS_MODELS_ASSETS_TYPE_ASSET, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	assets = _tmp0_;
	_tmp1_ = json_object_get_object_member (release, "assets");
	_tmp2_ = _json_object_ref0 (_tmp1_);
	container = _tmp2_;
	_tmp4_ = container;
	if (_tmp4_ != NULL) {
		JsonObject* _tmp5_;
		JsonArray* _tmp6_;
		_tmp5_ = container;
		_tmp6_ = json_object_get_array_member (_tmp5_, "links");
		_tmp3_ = _tmp6_;
	} else {
		_tmp3_ = NULL;
	}
	_tmp7_ = _json_array_ref0 (_tmp3_);
	array = _tmp7_;
	_tmp8_ = array;
	if (_tmp8_ == NULL) {
		result = assets;
		_json_array_unref0 (array);
		_json_object_unref0 (container);
		return result;
	}
	{
		gint index = 0;
		index = 0;
		{
			gboolean _tmp9_ = FALSE;
			_tmp9_ = TRUE;
			while (TRUE) {
				JsonArray* _tmp11_;
				JsonObject* object = NULL;
				JsonArray* _tmp12_;
				JsonObject* _tmp13_;
				JsonObject* _tmp14_;
				JsonObject* _tmp15_;
				gchar* name = NULL;
				JsonObject* _tmp16_;
				const gchar* _tmp17_;
				gchar* _tmp18_;
				gchar* download_url = NULL;
				JsonObject* _tmp19_;
				const gchar* _tmp20_;
				gchar* _tmp21_;
				gboolean _tmp22_ = FALSE;
				gboolean _tmp23_ = FALSE;
				const gchar* _tmp24_;
				gint64 _tmp27_ = 0LL;
				JsonObject* _tmp28_;
				GeeLinkedList* _tmp30_;
				const gchar* _tmp31_;
				const gchar* _tmp32_;
				JsonObject* _tmp33_;
				const gchar* _tmp34_;
				ProtonPlusModelsAssetsAsset* _tmp35_;
				ProtonPlusModelsAssetsAsset* _tmp36_;
				if (!_tmp9_) {
					gint _tmp10_;
					_tmp10_ = index;
					index = _tmp10_ + 1;
				}
				_tmp9_ = FALSE;
				_tmp11_ = array;
				if (!(((guint) index) < json_array_get_length (_tmp11_))) {
					break;
				}
				_tmp12_ = array;
				_tmp13_ = json_array_get_object_element (_tmp12_, (guint) index);
				_tmp14_ = _json_object_ref0 (_tmp13_);
				object = _tmp14_;
				_tmp15_ = object;
				if (_tmp15_ == NULL) {
					_json_object_unref0 (object);
					continue;
				}
				_tmp16_ = object;
				_tmp17_ = json_object_get_string_member_with_default (_tmp16_, "name", "");
				_tmp18_ = g_strdup (_tmp17_);
				name = _tmp18_;
				_tmp19_ = object;
				_tmp20_ = json_object_get_string_member_with_default (_tmp19_, "direct_asset_url", "");
				_tmp21_ = string_replace (_tmp20_, "?ref_type=heads", "");
				download_url = _tmp21_;
				_tmp24_ = name;
				if (g_strcmp0 (_tmp24_, "") == 0) {
					_tmp23_ = TRUE;
				} else {
					const gchar* _tmp25_;
					_tmp25_ = download_url;
					_tmp23_ = g_strcmp0 (_tmp25_, "") == 0;
				}
				if (_tmp23_) {
					_tmp22_ = TRUE;
				} else {
					const gchar* _tmp26_;
					_tmp26_ = name;
					_tmp22_ = !proton_plus_models_assets_asset_is_archive_name (_tmp26_);
				}
				if (_tmp22_) {
					_g_free0 (download_url);
					_g_free0 (name);
					_json_object_unref0 (object);
					continue;
				}
				_tmp28_ = object;
				if (json_object_has_member (_tmp28_, "size")) {
					JsonObject* _tmp29_;
					_tmp29_ = object;
					_tmp27_ = json_object_get_int_member (_tmp29_, "size");
				} else {
					_tmp27_ = (gint64) 0;
				}
				_tmp30_ = assets;
				_tmp31_ = name;
				_tmp32_ = download_url;
				_tmp33_ = object;
				_tmp34_ = json_object_get_string_member_with_default (_tmp33_, "digest", "");
				_tmp35_ = proton_plus_models_assets_asset_new (_tmp31_, _tmp32_, _tmp27_, _tmp34_);
				_tmp36_ = _tmp35_;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp30_, _tmp36_);
				_g_object_unref0 (_tmp36_);
				_g_free0 (download_url);
				_g_free0 (name);
				_json_object_unref0 (object);
			}
		}
	}
	result = assets;
	_json_array_unref0 (array);
	_json_object_unref0 (container);
	return result;
}

ProtonPlusProvidersSourcesGitLabReleaseSource*
proton_plus_providers_sources_git_lab_release_source_construct (GType object_type)
{
	ProtonPlusProvidersSourcesGitLabReleaseSource * self = NULL;
	self = (ProtonPlusProvidersSourcesGitLabReleaseSource*) g_object_new (object_type, NULL);
	return self;
}

ProtonPlusProvidersSourcesGitLabReleaseSource*
proton_plus_providers_sources_git_lab_release_source_new (void)
{
	return proton_plus_providers_sources_git_lab_release_source_construct (PROTON_PLUS_PROVIDERS_SOURCES_TYPE_GIT_LAB_RELEASE_SOURCE);
}

static void
proton_plus_providers_sources_git_lab_release_source_class_init (ProtonPlusProvidersSourcesGitLabReleaseSourceClass * klass,
                                                                 gpointer klass_data)
{
	proton_plus_providers_sources_git_lab_release_source_parent_class = g_type_class_peek_parent (klass);
}

static void
proton_plus_providers_sources_git_lab_release_source_proton_plus_providers_sources_release_source_interface_init (ProtonPlusProvidersSourcesReleaseSourceIface * iface,
                                                                                                                  gpointer iface_data)
{
	proton_plus_providers_sources_git_lab_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_lab_release_source_real_fetch_page;
	iface->fetch_page_finish = (ProtonPlusModelsToolsReleasePageResult* (*) (ProtonPlusProvidersSourcesReleaseSource*, GAsyncResult*)) proton_plus_providers_sources_git_lab_release_source_fetch_page_finish;
}

static void
proton_plus_providers_sources_git_lab_release_source_instance_init (ProtonPlusProvidersSourcesGitLabReleaseSource * self,
                                                                    gpointer klass)
{
}

static GType
proton_plus_providers_sources_git_lab_release_source_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusProvidersSourcesGitLabReleaseSourceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_providers_sources_git_lab_release_source_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusProvidersSourcesGitLabReleaseSource), 0, (GInstanceInitFunc) proton_plus_providers_sources_git_lab_release_source_instance_init, NULL };
	static const GInterfaceInfo proton_plus_providers_sources_release_source_info = { (GInterfaceInitFunc) proton_plus_providers_sources_git_lab_release_source_proton_plus_providers_sources_release_source_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType proton_plus_providers_sources_git_lab_release_source_type_id;
	proton_plus_providers_sources_git_lab_release_source_type_id = g_type_register_static (G_TYPE_OBJECT, "ProtonPlusProvidersSourcesGitLabReleaseSource", &g_define_type_info, 0);
	g_type_add_interface_static (proton_plus_providers_sources_git_lab_release_source_type_id, PROTON_PLUS_PROVIDERS_SOURCES_TYPE_RELEASE_SOURCE, &proton_plus_providers_sources_release_source_info);
	return proton_plus_providers_sources_git_lab_release_source_type_id;
}

GType
proton_plus_providers_sources_git_lab_release_source_get_type (void)
{
	static volatile gsize proton_plus_providers_sources_git_lab_release_source_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_providers_sources_git_lab_release_source_type_id__once)) {
		GType proton_plus_providers_sources_git_lab_release_source_type_id;
		proton_plus_providers_sources_git_lab_release_source_type_id = proton_plus_providers_sources_git_lab_release_source_get_type_once ();
		g_once_init_leave (&proton_plus_providers_sources_git_lab_release_source_type_id__once, proton_plus_providers_sources_git_lab_release_source_type_id);
	}
	return proton_plus_providers_sources_git_lab_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;
}

