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

#include "protonplus_core.h"
#include <stdlib.h>
#include <string.h>
#include <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_CATALOG_RELEASE_BUILDER_0_PROPERTY,
	PROTON_PLUS_PROVIDERS_SOURCES_CATALOG_RELEASE_BUILDER_NUM_PROPERTIES
};
static GParamSpec* proton_plus_providers_sources_catalog_release_builder_properties[PROTON_PLUS_PROVIDERS_SOURCES_CATALOG_RELEASE_BUILDER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gpointer proton_plus_providers_sources_catalog_release_builder_parent_class = NULL;

static ProtonPlusModelsAssetsAsset* proton_plus_providers_sources_catalog_release_builder_find_variant_asset (ProtonPlusModelsProvidersVariantDefinition* variant,
                                                                                                       const gchar* title,
                                                                                                       const gchar* release_name,
                                                                                                       const gchar* tag_name,
                                                                                                       GeeLinkedList* assets);
static gchar* proton_plus_providers_sources_catalog_release_builder_render_asset_format (const gchar* format,
                                                                                  const gchar* title,
                                                                                  const gchar* release_name,
                                                                                  const gchar* tag_name);
static gboolean proton_plus_providers_sources_catalog_release_builder_variant_matches_asset (const gchar* expected_asset_name,
                                                                                      const gchar* asset_name);
static GType proton_plus_providers_sources_catalog_release_builder_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

gboolean
proton_plus_providers_sources_catalog_release_builder_is_eligible (ProtonPlusModelsProvidersProviderDefinition* definition,
                                                                   const gchar* release_title)
{
	gchar** _tmp0_;
	gint _tmp0__length1;
	gint _tmp1_ = 0;
	gchar** _tmp2_;
	gint _tmp2__length1;
	gchar** _tmp3_;
	gint _tmp3__length1;
	gboolean _tmp4_;
	gchar** _tmp10_;
	gint _tmp10__length1;
	gint _tmp11_ = 0;
	gchar** _tmp12_;
	gint _tmp12__length1;
	gboolean result;
	g_return_val_if_fail (definition != NULL, FALSE);
	g_return_val_if_fail (release_title != NULL, FALSE);
	_tmp0_ = proton_plus_models_providers_provider_definition_get_asset_filters (definition, &_tmp1_);
	_tmp0__length1 = _tmp1_;
	_tmp2_ = _tmp0_;
	_tmp2__length1 = _tmp0__length1;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = _tmp2__length1;
	_tmp4_ = _tmp2__length1 > 0;
	_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL);
	if (_tmp4_) {
		gchar** _tmp5_;
		gint _tmp5__length1;
		gint _tmp6_ = 0;
		gchar** _tmp7_;
		gint _tmp7__length1;
		_tmp5_ = proton_plus_models_providers_provider_definition_get_asset_filters (definition, &_tmp6_);
		_tmp5__length1 = _tmp6_;
		_tmp7_ = _tmp5_;
		_tmp7__length1 = _tmp5__length1;
		{
			gchar** filter_collection = NULL;
			gint filter_collection_length1 = 0;
			gint _filter_collection_size_ = 0;
			gint filter_it = 0;
			filter_collection = _tmp7_;
			filter_collection_length1 = _tmp7__length1;
			for (filter_it = 0; filter_it < filter_collection_length1; filter_it = filter_it + 1) {
				gchar* _tmp8_;
				gchar* filter = NULL;
				_tmp8_ = g_strdup (filter_collection[filter_it]);
				filter = _tmp8_;
				{
					const gchar* _tmp9_;
					_tmp9_ = filter;
					if (!string_contains (release_title, _tmp9_)) {
						result = FALSE;
						_g_free0 (filter);
						filter_collection = (_vala_array_free (filter_collection, filter_collection_length1, (GDestroyNotify) g_free), NULL);
						return result;
					}
					_g_free0 (filter);
				}
			}
			filter_collection = (_vala_array_free (filter_collection, filter_collection_length1, (GDestroyNotify) g_free), NULL);
		}
		result = TRUE;
		return result;
	}
	_tmp10_ = proton_plus_models_providers_provider_definition_get_asset_exclusions (definition, &_tmp11_);
	_tmp10__length1 = _tmp11_;
	_tmp12_ = _tmp10_;
	_tmp12__length1 = _tmp10__length1;
	{
		gchar** exclusion_collection = NULL;
		gint exclusion_collection_length1 = 0;
		gint _exclusion_collection_size_ = 0;
		gint exclusion_it = 0;
		exclusion_collection = _tmp12_;
		exclusion_collection_length1 = _tmp12__length1;
		for (exclusion_it = 0; exclusion_it < exclusion_collection_length1; exclusion_it = exclusion_it + 1) {
			gchar* _tmp13_;
			gchar* exclusion = NULL;
			_tmp13_ = g_strdup (exclusion_collection[exclusion_it]);
			exclusion = _tmp13_;
			{
				const gchar* _tmp14_;
				_tmp14_ = exclusion;
				if (string_contains (release_title, _tmp14_)) {
					result = FALSE;
					_g_free0 (exclusion);
					exclusion_collection = (_vala_array_free (exclusion_collection, exclusion_collection_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				_g_free0 (exclusion);
			}
		}
		exclusion_collection = (_vala_array_free (exclusion_collection, exclusion_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	result = TRUE;
	return result;
}

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

GeeLinkedList*
proton_plus_providers_sources_catalog_release_builder_create_variants (ProtonPlusModelsProvidersProviderDefinition* definition,
                                                                       const gchar* release_name,
                                                                       const gchar* tag_name,
                                                                       GeeLinkedList* assets)
{
	GeeLinkedList* variants = NULL;
	GeeLinkedList* _tmp0_;
	gint _tmp1_ = 0;
	ProtonPlusModelsProvidersVariantDefinition** _tmp2_;
	GeeLinkedList* result;
	g_return_val_if_fail (definition != NULL, NULL);
	g_return_val_if_fail (release_name != NULL, NULL);
	g_return_val_if_fail (tag_name != NULL, NULL);
	g_return_val_if_fail (assets != NULL, NULL);
	_tmp0_ = gee_linked_list_new (PROTON_PLUS_MODELS_TYPE_VARIANT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	variants = _tmp0_;
	_tmp2_ = proton_plus_models_providers_provider_definition_get_variants (definition, &_tmp1_);
	{
		ProtonPlusModelsProvidersVariantDefinition** definition_variant_collection = NULL;
		gint definition_variant_collection_length1 = 0;
		gint _definition_variant_collection_size_ = 0;
		gint definition_variant_it = 0;
		definition_variant_collection = _tmp2_;
		definition_variant_collection_length1 = _tmp1_;
		for (definition_variant_it = 0; definition_variant_it < definition_variant_collection_length1; definition_variant_it = definition_variant_it + 1) {
			ProtonPlusModelsProvidersVariantDefinition* _tmp3_;
			ProtonPlusModelsProvidersVariantDefinition* definition_variant = NULL;
			_tmp3_ = _g_object_ref0 (definition_variant_collection[definition_variant_it]);
			definition_variant = _tmp3_;
			{
				ProtonPlusModelsAssetsAsset* selected_asset = NULL;
				ProtonPlusModelsProvidersVariantDefinition* _tmp4_;
				const gchar* _tmp5_;
				const gchar* _tmp6_;
				ProtonPlusModelsAssetsAsset* _tmp7_;
				ProtonPlusModelsAssetsAsset* _tmp8_ = NULL;
				ProtonPlusModelsAssetsAsset* _tmp9_;
				const gchar* _tmp10_ = NULL;
				gchar* download_url = NULL;
				gchar* _tmp13_;
				gboolean _tmp14_ = FALSE;
				gboolean _tmp15_ = FALSE;
				gboolean _tmp16_ = FALSE;
				const gchar* _tmp17_;
				GeeLinkedList* _tmp31_;
				ProtonPlusModelsProvidersVariantDefinition* _tmp32_;
				const gchar* _tmp33_;
				const gchar* _tmp34_;
				ProtonPlusModelsProvidersVariantDefinition* _tmp35_;
				const gchar* _tmp36_;
				const gchar* _tmp37_;
				ProtonPlusModelsProvidersVariantDefinition* _tmp38_;
				const gchar* _tmp39_;
				const gchar* _tmp40_;
				ProtonPlusModelsProvidersVariantDefinition* _tmp41_;
				gboolean _tmp42_;
				gboolean _tmp43_;
				const gchar* _tmp44_;
				ProtonPlusModelsProvidersVariantDefinition* _tmp45_;
				ProtonPlusModelsVariantCompatibility* _tmp46_;
				ProtonPlusModelsVariantCompatibility* _tmp47_;
				ProtonPlusModelsAssetsAsset* _tmp48_;
				ProtonPlusModelsVariant* _tmp49_;
				ProtonPlusModelsVariant* _tmp50_;
				_tmp4_ = definition_variant;
				_tmp5_ = proton_plus_models_providers_provider_definition_get_title (definition);
				_tmp6_ = _tmp5_;
				_tmp7_ = proton_plus_providers_sources_catalog_release_builder_find_variant_asset (_tmp4_, _tmp6_, release_name, tag_name, assets);
				selected_asset = _tmp7_;
				_tmp9_ = selected_asset;
				_tmp8_ = _tmp9_;
				_tmp10_ = NULL;
				if (_tmp8_ != NULL) {
					const gchar* _tmp11_;
					const gchar* _tmp12_;
					_tmp11_ = proton_plus_models_assets_asset_get_download_url (_tmp8_);
					_tmp12_ = _tmp11_;
					_tmp10_ = _tmp12_;
				}
				_tmp13_ = g_strdup (_tmp10_);
				download_url = _tmp13_;
				_tmp17_ = download_url;
				if (_tmp17_ == NULL) {
					ProtonPlusModelsProvidersVariantDefinition* _tmp18_;
					gboolean _tmp19_;
					gboolean _tmp20_;
					_tmp18_ = definition_variant;
					_tmp19_ = proton_plus_models_providers_variant_definition_get_is_default (_tmp18_);
					_tmp20_ = _tmp19_;
					_tmp16_ = _tmp20_;
				} else {
					_tmp16_ = FALSE;
				}
				if (_tmp16_) {
					gboolean _tmp21_;
					gboolean _tmp22_;
					_tmp21_ = proton_plus_models_providers_provider_definition_get_single_archive_releases (definition);
					_tmp22_ = _tmp21_;
					_tmp15_ = _tmp22_;
				} else {
					_tmp15_ = FALSE;
				}
				if (_tmp15_) {
					gint _tmp23_;
					gint _tmp24_;
					_tmp23_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) assets);
					_tmp24_ = _tmp23_;
					_tmp14_ = _tmp24_ == 1;
				} else {
					_tmp14_ = FALSE;
				}
				if (_tmp14_) {
					gpointer _tmp25_;
					ProtonPlusModelsAssetsAsset* _tmp26_;
					_tmp25_ = gee_linked_list_first (assets);
					_g_object_unref0 (selected_asset);
					selected_asset = (ProtonPlusModelsAssetsAsset*) _tmp25_;
					_tmp26_ = selected_asset;
					if (_tmp26_ != NULL) {
						ProtonPlusModelsAssetsAsset* _tmp27_;
						const gchar* _tmp28_;
						const gchar* _tmp29_;
						gchar* _tmp30_;
						_tmp27_ = selected_asset;
						_tmp28_ = proton_plus_models_assets_asset_get_download_url (_tmp27_);
						_tmp29_ = _tmp28_;
						_tmp30_ = g_strdup (_tmp29_);
						_g_free0 (download_url);
						download_url = _tmp30_;
					}
				}
				_tmp31_ = variants;
				_tmp32_ = definition_variant;
				_tmp33_ = proton_plus_models_providers_variant_definition_get_id (_tmp32_);
				_tmp34_ = _tmp33_;
				_tmp35_ = definition_variant;
				_tmp36_ = proton_plus_models_providers_variant_definition_get_name (_tmp35_);
				_tmp37_ = _tmp36_;
				_tmp38_ = definition_variant;
				_tmp39_ = proton_plus_models_providers_variant_definition_get_format (_tmp38_);
				_tmp40_ = _tmp39_;
				_tmp41_ = definition_variant;
				_tmp42_ = proton_plus_models_providers_variant_definition_get_is_default (_tmp41_);
				_tmp43_ = _tmp42_;
				_tmp44_ = download_url;
				_tmp45_ = definition_variant;
				_tmp46_ = proton_plus_models_providers_variant_definition_get_compatibility (_tmp45_);
				_tmp47_ = _tmp46_;
				_tmp48_ = selected_asset;
				_tmp49_ = proton_plus_models_variant_new (_tmp34_, _tmp37_, _tmp40_, _tmp43_, _tmp44_, _tmp47_, _tmp48_);
				_tmp50_ = _tmp49_;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp31_, _tmp50_);
				_g_object_unref0 (_tmp50_);
				_g_free0 (download_url);
				_g_object_unref0 (selected_asset);
				_g_object_unref0 (definition_variant);
			}
		}
		definition_variant_collection = (_vala_array_free (definition_variant_collection, definition_variant_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	result = variants;
	return result;
}

ProtonPlusModelsAssetsAsset*
proton_plus_providers_sources_catalog_release_builder_select_default_asset (GeeLinkedList* assets,
                                                                            GeeLinkedList* variants)
{
	ProtonPlusModelsAssetsAsset* result;
	g_return_val_if_fail (assets != NULL, NULL);
	g_return_val_if_fail (variants != NULL, NULL);
	{
		GeeLinkedList* _variant_list = NULL;
		gint _variant_size = 0;
		GeeLinkedList* _tmp0_;
		gint _tmp1_;
		gint _tmp2_;
		gint _variant_index = 0;
		_variant_list = variants;
		_tmp0_ = _variant_list;
		_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
		_tmp2_ = _tmp1_;
		_variant_size = _tmp2_;
		_variant_index = -1;
		while (TRUE) {
			gint _tmp3_;
			gint _tmp4_;
			ProtonPlusModelsVariant* variant = NULL;
			GeeLinkedList* _tmp5_;
			gpointer _tmp6_;
			gboolean _tmp7_ = FALSE;
			gboolean _tmp8_ = FALSE;
			ProtonPlusModelsVariant* _tmp9_;
			gboolean _tmp10_;
			gboolean _tmp11_;
			_variant_index = _variant_index + 1;
			_tmp3_ = _variant_index;
			_tmp4_ = _variant_size;
			if (!(_tmp3_ < _tmp4_)) {
				break;
			}
			_tmp5_ = _variant_list;
			_tmp6_ = gee_abstract_list_get ((GeeAbstractList*) _tmp5_, _variant_index);
			variant = (ProtonPlusModelsVariant*) _tmp6_;
			_tmp9_ = variant;
			_tmp10_ = proton_plus_models_variant_get_is_default (_tmp9_);
			_tmp11_ = _tmp10_;
			if (!_tmp11_) {
				_tmp8_ = TRUE;
			} else {
				ProtonPlusModelsVariant* _tmp12_;
				const gchar* _tmp13_;
				const gchar* _tmp14_;
				_tmp12_ = variant;
				_tmp13_ = proton_plus_models_variant_get_download_url (_tmp12_);
				_tmp14_ = _tmp13_;
				_tmp8_ = _tmp14_ == NULL;
			}
			if (_tmp8_) {
				_tmp7_ = TRUE;
			} else {
				ProtonPlusModelsVariant* _tmp15_;
				const gchar* _tmp16_;
				const gchar* _tmp17_;
				_tmp15_ = variant;
				_tmp16_ = proton_plus_models_variant_get_download_url (_tmp15_);
				_tmp17_ = _tmp16_;
				_tmp7_ = g_strcmp0 (_tmp17_, "") == 0;
			}
			if (_tmp7_) {
				_g_object_unref0 (variant);
				continue;
			}
			{
				GeeLinkedList* _asset_list = NULL;
				gint _asset_size = 0;
				GeeLinkedList* _tmp18_;
				gint _tmp19_;
				gint _tmp20_;
				gint _asset_index = 0;
				_asset_list = assets;
				_tmp18_ = _asset_list;
				_tmp19_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp18_);
				_tmp20_ = _tmp19_;
				_asset_size = _tmp20_;
				_asset_index = -1;
				while (TRUE) {
					gint _tmp21_;
					gint _tmp22_;
					ProtonPlusModelsAssetsAsset* asset = NULL;
					GeeLinkedList* _tmp23_;
					gpointer _tmp24_;
					ProtonPlusModelsAssetsAsset* _tmp25_;
					const gchar* _tmp26_;
					const gchar* _tmp27_;
					ProtonPlusModelsVariant* _tmp28_;
					const gchar* _tmp29_;
					const gchar* _tmp30_;
					_asset_index = _asset_index + 1;
					_tmp21_ = _asset_index;
					_tmp22_ = _asset_size;
					if (!(_tmp21_ < _tmp22_)) {
						break;
					}
					_tmp23_ = _asset_list;
					_tmp24_ = gee_abstract_list_get ((GeeAbstractList*) _tmp23_, _asset_index);
					asset = (ProtonPlusModelsAssetsAsset*) _tmp24_;
					_tmp25_ = asset;
					_tmp26_ = proton_plus_models_assets_asset_get_download_url (_tmp25_);
					_tmp27_ = _tmp26_;
					_tmp28_ = variant;
					_tmp29_ = proton_plus_models_variant_get_download_url (_tmp28_);
					_tmp30_ = _tmp29_;
					if (g_strcmp0 (_tmp27_, _tmp30_) == 0) {
						result = asset;
						_g_object_unref0 (variant);
						return result;
					}
					_g_object_unref0 (asset);
				}
			}
			_g_object_unref0 (variant);
		}
	}
	result = NULL;
	return result;
}

gboolean
proton_plus_providers_sources_catalog_release_builder_default_variant_matches_asset (ProtonPlusModelsProvidersProviderDefinition* definition,
                                                                                     const gchar* release_name,
                                                                                     const gchar* tag_name,
                                                                                     ProtonPlusModelsAssetsAsset* asset)
{
	gint _tmp0_ = 0;
	ProtonPlusModelsProvidersVariantDefinition** _tmp1_;
	gboolean result;
	g_return_val_if_fail (definition != NULL, FALSE);
	g_return_val_if_fail (release_name != NULL, FALSE);
	g_return_val_if_fail (tag_name != NULL, FALSE);
	g_return_val_if_fail (asset != NULL, FALSE);
	_tmp1_ = proton_plus_models_providers_provider_definition_get_variants (definition, &_tmp0_);
	{
		ProtonPlusModelsProvidersVariantDefinition** variant_collection = NULL;
		gint variant_collection_length1 = 0;
		gint _variant_collection_size_ = 0;
		gint variant_it = 0;
		variant_collection = _tmp1_;
		variant_collection_length1 = _tmp0_;
		for (variant_it = 0; variant_it < variant_collection_length1; variant_it = variant_it + 1) {
			ProtonPlusModelsProvidersVariantDefinition* _tmp2_;
			ProtonPlusModelsProvidersVariantDefinition* variant = NULL;
			_tmp2_ = _g_object_ref0 (variant_collection[variant_it]);
			variant = _tmp2_;
			{
				ProtonPlusModelsProvidersVariantDefinition* _tmp3_;
				gboolean _tmp4_;
				gboolean _tmp5_;
				ProtonPlusModelsProvidersVariantDefinition* _tmp6_;
				gint _tmp7_ = 0;
				gchar** _tmp8_;
				_tmp3_ = variant;
				_tmp4_ = proton_plus_models_providers_variant_definition_get_is_default (_tmp3_);
				_tmp5_ = _tmp4_;
				if (!_tmp5_) {
					_g_object_unref0 (variant);
					continue;
				}
				_tmp6_ = variant;
				_tmp8_ = proton_plus_models_providers_variant_definition_get_asset_formats (_tmp6_, &_tmp7_);
				{
					gchar** format_collection = NULL;
					gint format_collection_length1 = 0;
					gint _format_collection_size_ = 0;
					gint format_it = 0;
					format_collection = _tmp8_;
					format_collection_length1 = _tmp7_;
					for (format_it = 0; format_it < format_collection_length1; format_it = format_it + 1) {
						gchar* _tmp9_;
						gchar* format = NULL;
						_tmp9_ = g_strdup (format_collection[format_it]);
						format = _tmp9_;
						{
							gchar* expected_name = NULL;
							const gchar* _tmp10_;
							const gchar* _tmp11_;
							const gchar* _tmp12_;
							gchar* _tmp13_;
							const gchar* _tmp14_;
							const gchar* _tmp15_;
							const gchar* _tmp16_;
							_tmp10_ = format;
							_tmp11_ = proton_plus_models_providers_provider_definition_get_title (definition);
							_tmp12_ = _tmp11_;
							_tmp13_ = proton_plus_providers_sources_catalog_release_builder_render_asset_format (_tmp10_, _tmp12_, release_name, tag_name);
							expected_name = _tmp13_;
							_tmp14_ = expected_name;
							_tmp15_ = proton_plus_models_assets_asset_get_name (asset);
							_tmp16_ = _tmp15_;
							if (proton_plus_providers_sources_catalog_release_builder_variant_matches_asset (_tmp14_, _tmp16_)) {
								result = TRUE;
								_g_free0 (expected_name);
								_g_free0 (format);
								format_collection = (_vala_array_free (format_collection, format_collection_length1, (GDestroyNotify) g_free), NULL);
								_g_object_unref0 (variant);
								variant_collection = (_vala_array_free (variant_collection, variant_collection_length1, (GDestroyNotify) g_object_unref), NULL);
								return result;
							}
							_g_free0 (expected_name);
							_g_free0 (format);
						}
					}
					format_collection = (_vala_array_free (format_collection, format_collection_length1, (GDestroyNotify) g_free), NULL);
				}
				result = FALSE;
				_g_object_unref0 (variant);
				variant_collection = (_vala_array_free (variant_collection, variant_collection_length1, (GDestroyNotify) g_object_unref), NULL);
				return result;
			}
		}
		variant_collection = (_vala_array_free (variant_collection, variant_collection_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	result = FALSE;
	return result;
}

gchar*
proton_plus_providers_sources_catalog_release_builder_render_asset_name (ProtonPlusModelsProvidersVariantDefinition* variant,
                                                                         const gchar* title,
                                                                         const gchar* release_name,
                                                                         const gchar* tag_name)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	g_return_val_if_fail (variant != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	g_return_val_if_fail (release_name != NULL, NULL);
	g_return_val_if_fail (tag_name != NULL, NULL);
	_tmp0_ = proton_plus_models_providers_variant_definition_get_format (variant);
	_tmp1_ = _tmp0_;
	_tmp2_ = proton_plus_providers_sources_catalog_release_builder_render_asset_format (_tmp1_, title, release_name, tag_name);
	result = _tmp2_;
	return result;
}

static ProtonPlusModelsAssetsAsset*
proton_plus_providers_sources_catalog_release_builder_find_variant_asset (ProtonPlusModelsProvidersVariantDefinition* variant,
                                                                          const gchar* title,
                                                                          const gchar* release_name,
                                                                          const gchar* tag_name,
                                                                          GeeLinkedList* assets)
{
	gint _tmp0_ = 0;
	gchar** _tmp1_;
	ProtonPlusModelsAssetsAsset* result;
	g_return_val_if_fail (variant != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	g_return_val_if_fail (release_name != NULL, NULL);
	g_return_val_if_fail (tag_name != NULL, NULL);
	g_return_val_if_fail (assets != NULL, NULL);
	_tmp1_ = proton_plus_models_providers_variant_definition_get_asset_formats (variant, &_tmp0_);
	{
		gchar** format_collection = NULL;
		gint format_collection_length1 = 0;
		gint _format_collection_size_ = 0;
		gint format_it = 0;
		format_collection = _tmp1_;
		format_collection_length1 = _tmp0_;
		for (format_it = 0; format_it < format_collection_length1; format_it = format_it + 1) {
			gchar* _tmp2_;
			gchar* format = NULL;
			_tmp2_ = g_strdup (format_collection[format_it]);
			format = _tmp2_;
			{
				gchar* expected_name = NULL;
				const gchar* _tmp3_;
				gchar* _tmp4_;
				_tmp3_ = format;
				_tmp4_ = proton_plus_providers_sources_catalog_release_builder_render_asset_format (_tmp3_, title, release_name, tag_name);
				expected_name = _tmp4_;
				{
					GeeLinkedList* _asset_list = NULL;
					gint _asset_size = 0;
					GeeLinkedList* _tmp5_;
					gint _tmp6_;
					gint _tmp7_;
					gint _asset_index = 0;
					_asset_list = assets;
					_tmp5_ = _asset_list;
					_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
					_tmp7_ = _tmp6_;
					_asset_size = _tmp7_;
					_asset_index = -1;
					while (TRUE) {
						gint _tmp8_;
						gint _tmp9_;
						ProtonPlusModelsAssetsAsset* asset = NULL;
						GeeLinkedList* _tmp10_;
						gpointer _tmp11_;
						const gchar* _tmp12_;
						ProtonPlusModelsAssetsAsset* _tmp13_;
						const gchar* _tmp14_;
						const gchar* _tmp15_;
						_asset_index = _asset_index + 1;
						_tmp8_ = _asset_index;
						_tmp9_ = _asset_size;
						if (!(_tmp8_ < _tmp9_)) {
							break;
						}
						_tmp10_ = _asset_list;
						_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, _asset_index);
						asset = (ProtonPlusModelsAssetsAsset*) _tmp11_;
						_tmp12_ = expected_name;
						_tmp13_ = asset;
						_tmp14_ = proton_plus_models_assets_asset_get_name (_tmp13_);
						_tmp15_ = _tmp14_;
						if (proton_plus_providers_sources_catalog_release_builder_variant_matches_asset (_tmp12_, _tmp15_)) {
							result = asset;
							_g_free0 (expected_name);
							_g_free0 (format);
							format_collection = (_vala_array_free (format_collection, format_collection_length1, (GDestroyNotify) g_free), NULL);
							return result;
						}
						_g_object_unref0 (asset);
					}
				}
				_g_free0 (expected_name);
				_g_free0 (format);
			}
		}
		format_collection = (_vala_array_free (format_collection, format_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	result = NULL;
	return result;
}

static gchar*
proton_plus_providers_sources_catalog_release_builder_render_asset_format (const gchar* format,
                                                                           const gchar* title,
                                                                           const gchar* release_name,
                                                                           const gchar* tag_name)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (format != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	g_return_val_if_fail (release_name != NULL, NULL);
	g_return_val_if_fail (tag_name != NULL, NULL);
	_tmp0_ = proton_plus_models_providers_provider_template_render (format, title, release_name, tag_name);
	result = _tmp0_;
	return result;
}

static gboolean
proton_plus_providers_sources_catalog_release_builder_variant_matches_asset (const gchar* expected_asset_name,
                                                                             const gchar* asset_name)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (expected_asset_name != NULL, FALSE);
	g_return_val_if_fail (asset_name != NULL, FALSE);
	if (g_strcmp0 (asset_name, expected_asset_name) == 0) {
		_tmp0_ = TRUE;
	} else {
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = proton_plus_utils_archive_helper_strip_archive_extension (asset_name, FALSE);
		_tmp2_ = _tmp1_;
		_tmp0_ = g_strcmp0 (_tmp2_, expected_asset_name) == 0;
		_g_free0 (_tmp2_);
	}
	result = _tmp0_;
	return result;
}

ProtonPlusProvidersSourcesCatalogReleaseBuilder*
proton_plus_providers_sources_catalog_release_builder_construct (GType object_type)
{
	ProtonPlusProvidersSourcesCatalogReleaseBuilder * self = NULL;
	self = (ProtonPlusProvidersSourcesCatalogReleaseBuilder*) g_object_new (object_type, NULL);
	return self;
}

ProtonPlusProvidersSourcesCatalogReleaseBuilder*
proton_plus_providers_sources_catalog_release_builder_new (void)
{
	return proton_plus_providers_sources_catalog_release_builder_construct (PROTON_PLUS_PROVIDERS_SOURCES_TYPE_CATALOG_RELEASE_BUILDER);
}

static void
proton_plus_providers_sources_catalog_release_builder_class_init (ProtonPlusProvidersSourcesCatalogReleaseBuilderClass * klass,
                                                                  gpointer klass_data)
{
	proton_plus_providers_sources_catalog_release_builder_parent_class = g_type_class_peek_parent (klass);
}

static void
proton_plus_providers_sources_catalog_release_builder_instance_init (ProtonPlusProvidersSourcesCatalogReleaseBuilder * self,
                                                                     gpointer klass)
{
}

static GType
proton_plus_providers_sources_catalog_release_builder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusProvidersSourcesCatalogReleaseBuilderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_providers_sources_catalog_release_builder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusProvidersSourcesCatalogReleaseBuilder), 0, (GInstanceInitFunc) proton_plus_providers_sources_catalog_release_builder_instance_init, NULL };
	GType proton_plus_providers_sources_catalog_release_builder_type_id;
	proton_plus_providers_sources_catalog_release_builder_type_id = g_type_register_static (G_TYPE_OBJECT, "ProtonPlusProvidersSourcesCatalogReleaseBuilder", &g_define_type_info, 0);
	return proton_plus_providers_sources_catalog_release_builder_type_id;
}

GType
proton_plus_providers_sources_catalog_release_builder_get_type (void)
{
	static volatile gsize proton_plus_providers_sources_catalog_release_builder_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_providers_sources_catalog_release_builder_type_id__once)) {
		GType proton_plus_providers_sources_catalog_release_builder_type_id;
		proton_plus_providers_sources_catalog_release_builder_type_id = proton_plus_providers_sources_catalog_release_builder_get_type_once ();
		g_once_init_leave (&proton_plus_providers_sources_catalog_release_builder_type_id__once, proton_plus_providers_sources_catalog_release_builder_type_id);
	}
	return proton_plus_providers_sources_catalog_release_builder_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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;
}

