/* media.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from media.vala, do not modify */

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include "gnome-games.h"
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.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  {
	GAMES_MEDIA_0_PROPERTY,
	GAMES_MEDIA_TITLE_PROPERTY,
	GAMES_MEDIA_NUM_PROPERTIES
};
static GParamSpec* games_media_properties[GAMES_MEDIA_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _games_uri_unref0(var) ((var == NULL) ? NULL : (var = (games_uri_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GamesMediaPrivate {
	GamesTitle* _title;
	GamesUri** uris;
	gint uris_length1;
	gint _uris_size_;
};

static gint GamesMedia_private_offset;
static gpointer games_media_parent_class = NULL;

static void games_media_set_title (GamesMedia* self,
                            GamesTitle* value);
static void _vala_array_add8 (GamesUri** * array,
                       gint* length,
                       gint* size,
                       GamesUri* value);
static GamesUri** _vala_array_dup4 (GamesUri** self,
                             gssize length);
static void _vala_array_add9 (GamesUri** * array,
                       gint* length,
                       gint* size,
                       GamesUri* value);
static void _vala_array_add10 (GVariant** * array,
                        gint* length,
                        gint* size,
                        GVariant* value);
static void games_media_finalize (GObject * obj);
static GType games_media_get_type_once (void);
static void _vala_games_media_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec);
static void _vala_games_media_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec);
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
games_media_get_instance_private (GamesMedia* self)
{
	return G_STRUCT_MEMBER_P (self, GamesMedia_private_offset);
}

GamesMedia*
games_media_construct (GType object_type,
                       GamesTitle* title)
{
	GamesMedia * self = NULL;
	GamesUri** _tmp0_;
	self = (GamesMedia*) g_object_new (object_type, NULL);
	games_media_set_title (self, title);
	_tmp0_ = g_new0 (GamesUri*, 0 + 1);
	self->priv->uris = (_vala_array_free (self->priv->uris, self->priv->uris_length1, (GDestroyNotify) games_uri_unref), NULL);
	self->priv->uris = _tmp0_;
	self->priv->uris_length1 = 0;
	self->priv->_uris_size_ = self->priv->uris_length1;
	return self;
}

GamesMedia*
games_media_new (GamesTitle* title)
{
	return games_media_construct (GAMES_TYPE_MEDIA, title);
}

static void
_vala_array_add8 (GamesUri** * array,
                  gint* length,
                  gint* size,
                  GamesUri* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GamesUri*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

GamesMedia*
games_media_construct_parse (GType object_type,
                             GVariant* variant)
{
	GamesMedia * self = NULL;
	GVariantType* _tmp0_;
	GVariantType* _tmp1_;
	const GVariantType* _tmp2_;
	GVariant* title_child = NULL;
	GVariant* _tmp3_;
	GVariant* uris_child = NULL;
	GVariant* _tmp4_;
	GVariant* maybe_title = NULL;
	GVariant* _tmp5_;
	GVariant* _tmp6_;
	GVariant* _tmp7_;
	GamesUri** _tmp12_;
	g_return_val_if_fail (variant != NULL, NULL);
	self = (GamesMedia*) g_object_new (object_type, NULL);
	_tmp0_ = games_media_get_variant_type ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_variant_get_type (variant);
	_vala_assert (g_variant_type_equal (_tmp1_, _tmp2_), "get_variant_type ().equal (variant.get_type ())");
	_g_variant_type_free0 (_tmp1_);
	_tmp3_ = g_variant_get_child_value (variant, (gsize) 0);
	title_child = _tmp3_;
	_tmp4_ = g_variant_get_child_value (variant, (gsize) 1);
	uris_child = _tmp4_;
	_tmp5_ = title_child;
	_tmp6_ = g_variant_get_maybe (_tmp5_);
	maybe_title = _tmp6_;
	_tmp7_ = maybe_title;
	if (_tmp7_ != NULL) {
		GVariant* _tmp8_;
		const gchar* _tmp9_;
		GamesGenericTitle* _tmp10_;
		GamesGenericTitle* _tmp11_;
		_tmp8_ = maybe_title;
		_tmp9_ = g_variant_get_string (_tmp8_, NULL);
		_tmp10_ = games_generic_title_new (_tmp9_);
		_tmp11_ = _tmp10_;
		games_media_set_title (self, (GamesTitle*) _tmp11_);
		_g_object_unref0 (_tmp11_);
	}
	_tmp12_ = g_new0 (GamesUri*, 0 + 1);
	self->priv->uris = (_vala_array_free (self->priv->uris, self->priv->uris_length1, (GDestroyNotify) games_uri_unref), NULL);
	self->priv->uris = _tmp12_;
	self->priv->uris_length1 = 0;
	self->priv->_uris_size_ = self->priv->uris_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp13_ = FALSE;
			_tmp13_ = TRUE;
			while (TRUE) {
				GVariant* _tmp15_;
				gchar* uri = NULL;
				GVariant* _tmp16_;
				GVariant* _tmp17_;
				GVariant* _tmp18_;
				const gchar* _tmp19_;
				gchar* _tmp20_;
				gchar* _tmp21_;
				const gchar* _tmp22_;
				GamesUri* _tmp23_;
				if (!_tmp13_) {
					gint _tmp14_;
					_tmp14_ = i;
					i = _tmp14_ + 1;
				}
				_tmp13_ = FALSE;
				_tmp15_ = uris_child;
				if (!(((gsize) i) < g_variant_n_children (_tmp15_))) {
					break;
				}
				_tmp16_ = uris_child;
				_tmp17_ = g_variant_get_child_value (_tmp16_, (gsize) i);
				_tmp18_ = _tmp17_;
				_tmp19_ = g_variant_get_string (_tmp18_, NULL);
				_tmp20_ = g_strdup (_tmp19_);
				_tmp21_ = _tmp20_;
				_g_variant_unref0 (_tmp18_);
				uri = _tmp21_;
				_tmp22_ = uri;
				_tmp23_ = games_uri_new (_tmp22_);
				_vala_array_add8 (&self->priv->uris, &self->priv->uris_length1, &self->priv->_uris_size_, _tmp23_);
				_g_free0 (uri);
			}
		}
	}
	_g_variant_unref0 (maybe_title);
	_g_variant_unref0 (uris_child);
	_g_variant_unref0 (title_child);
	return self;
}

GamesMedia*
games_media_new_parse (GVariant* variant)
{
	return games_media_construct_parse (GAMES_TYPE_MEDIA, variant);
}

static gpointer
_games_uri_ref0 (gpointer self)
{
	return self ? games_uri_ref (self) : NULL;
}

static GamesUri**
_vala_array_dup4 (GamesUri** self,
                  gssize length)
{
	if (length >= 0) {
		GamesUri** result;
		gssize i;
		result = g_new0 (GamesUri*, length + 1);
		for (i = 0; i < length; i++) {
			GamesUri* _tmp0_;
			_tmp0_ = _games_uri_ref0 (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

GamesUri**
games_media_get_uris (GamesMedia* self,
                      gint* result_length1)
{
	GamesUri** _tmp0_;
	gint _tmp0__length1;
	GamesUri** _tmp1_;
	gint _tmp1__length1;
	GamesUri** _tmp2_;
	gint _tmp2__length1;
	GamesUri** result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->uris;
	_tmp0__length1 = self->priv->uris_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup4 (_tmp0_, _tmp0__length1) : _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static void
_vala_array_add9 (GamesUri** * array,
                  gint* length,
                  gint* size,
                  GamesUri* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GamesUri*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

void
games_media_add_uri (GamesMedia* self,
                     GamesUri* uri)
{
	GamesUri* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (uri != NULL);
	_tmp0_ = _games_uri_ref0 (uri);
	_vala_array_add9 (&self->priv->uris, &self->priv->uris_length1, &self->priv->_uris_size_, _tmp0_);
}

static void
_vala_array_add10 (GVariant** * array,
                   gint* length,
                   gint* size,
                   GVariant* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GVariant*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

GVariant*
games_media_serialize (GamesMedia* self)
{
	GVariant* title_variant = NULL;
	GamesTitle* _tmp0_;
	GVariant** uri_variants = NULL;
	GVariant** _tmp7_;
	gint uri_variants_length1;
	gint _uri_variants_size_;
	GamesUri** _tmp8_;
	gint _tmp8__length1;
	const GVariantType* _tmp14_;
	GVariant* _tmp15_;
	GVariant* _tmp16_;
	const GVariantType* _tmp17_;
	GVariant** _tmp18_;
	gint _tmp18__length1;
	GVariant* _tmp19_;
	GVariant** _tmp20_;
	GVariant** _tmp21_;
	gint _tmp21__length1;
	GVariant* _tmp22_;
	GVariant* _tmp23_;
	GError* _inner_error0_ = NULL;
	GVariant* result;
	g_return_val_if_fail (self != NULL, NULL);
	title_variant = NULL;
	_tmp0_ = self->priv->_title;
	if (_tmp0_ != NULL) {
		{
			gchar* _tmp1_ = NULL;
			GamesTitle* _tmp2_;
			gchar* _tmp3_;
			GVariant* _tmp4_;
			_tmp2_ = self->priv->_title;
			_tmp3_ = games_title_get_title (_tmp2_, &_inner_error0_);
			_tmp1_ = _tmp3_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp4_ = g_variant_new_string (_tmp1_);
			g_variant_ref_sink (_tmp4_);
			_g_variant_unref0 (title_variant);
			title_variant = _tmp4_;
			_g_free0 (_tmp1_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp5_;
			const gchar* _tmp6_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp5_ = e;
			_tmp6_ = _tmp5_->message;
			g_critical ("media.vala:45: Couldn't get title: %s", _tmp6_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_variant_unref0 (title_variant);
			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;
		}
	}
	_tmp7_ = g_new0 (GVariant*, 0 + 1);
	uri_variants = _tmp7_;
	uri_variants_length1 = 0;
	_uri_variants_size_ = uri_variants_length1;
	_tmp8_ = self->priv->uris;
	_tmp8__length1 = self->priv->uris_length1;
	{
		GamesUri** uri_collection = NULL;
		gint uri_collection_length1 = 0;
		gint _uri_collection_size_ = 0;
		gint uri_it = 0;
		uri_collection = _tmp8_;
		uri_collection_length1 = _tmp8__length1;
		for (uri_it = 0; uri_it < uri_collection_length1; uri_it = uri_it + 1) {
			GamesUri* _tmp9_;
			GamesUri* uri = NULL;
			_tmp9_ = _games_uri_ref0 (uri_collection[uri_it]);
			uri = _tmp9_;
			{
				GamesUri* _tmp10_;
				gchar* _tmp11_;
				gchar* _tmp12_;
				GVariant* _tmp13_;
				_tmp10_ = uri;
				_tmp11_ = games_uri_to_string (_tmp10_);
				_tmp12_ = _tmp11_;
				_tmp13_ = g_variant_new_string (_tmp12_);
				g_variant_ref_sink (_tmp13_);
				_vala_array_add10 (&uri_variants, &uri_variants_length1, &_uri_variants_size_, _tmp13_);
				_g_free0 (_tmp12_);
				_games_uri_unref0 (uri);
			}
		}
	}
	_tmp14_ = G_VARIANT_TYPE_STRING;
	_tmp15_ = title_variant;
	_tmp16_ = g_variant_new_maybe (_tmp14_, _tmp15_);
	g_variant_ref_sink (_tmp16_);
	_tmp17_ = G_VARIANT_TYPE_STRING;
	_tmp18_ = uri_variants;
	_tmp18__length1 = uri_variants_length1;
	_tmp19_ = g_variant_new_array (_tmp17_, _tmp18_, _tmp18__length1);
	g_variant_ref_sink (_tmp19_);
	_tmp20_ = g_new0 (GVariant*, 2 + 1);
	_tmp20_[0] = _tmp16_;
	_tmp20_[1] = _tmp19_;
	_tmp21_ = _tmp20_;
	_tmp21__length1 = 2;
	_tmp22_ = g_variant_new_tuple (_tmp21_, 2);
	g_variant_ref_sink (_tmp22_);
	_tmp23_ = _tmp22_;
	_tmp21_ = (_vala_array_free (_tmp21_, _tmp21__length1, (GDestroyNotify) g_variant_unref), NULL);
	result = _tmp23_;
	uri_variants = (_vala_array_free (uri_variants, uri_variants_length1, (GDestroyNotify) g_variant_unref), NULL);
	_g_variant_unref0 (title_variant);
	return result;
}

GVariantType*
games_media_get_variant_type (void)
{
	const GVariantType* _tmp0_;
	GVariantType* _tmp1_;
	const GVariantType* _tmp2_;
	GVariantType* _tmp3_;
	GVariantType** _tmp4_;
	GVariantType** _tmp5_;
	gint _tmp5__length1;
	GVariantType* _tmp6_;
	GVariantType* _tmp7_;
	GVariantType* result;
	_tmp0_ = G_VARIANT_TYPE_STRING;
	_tmp1_ = g_variant_type_new_maybe (_tmp0_);
	_tmp2_ = G_VARIANT_TYPE_STRING;
	_tmp3_ = g_variant_type_new_array (_tmp2_);
	_tmp4_ = g_new0 (GVariantType*, 2 + 1);
	_tmp4_[0] = _tmp1_;
	_tmp4_[1] = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp5__length1 = 2;
	_tmp6_ = g_variant_type_new_tuple (_tmp5_, 2);
	_tmp7_ = _tmp6_;
	_tmp5_ = (_vala_array_free (_tmp5_, _tmp5__length1, (GDestroyNotify) g_variant_type_free), NULL);
	result = _tmp7_;
	return result;
}

GamesTitle*
games_media_get_title (GamesMedia* self)
{
	GamesTitle* result;
	GamesTitle* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_title;
	result = _tmp0_;
	return result;
}

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

static void
games_media_set_title (GamesMedia* self,
                       GamesTitle* value)
{
	GamesTitle* old_value;
	g_return_if_fail (self != NULL);
	old_value = games_media_get_title (self);
	if (old_value != value) {
		GamesTitle* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_title);
		self->priv->_title = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, games_media_properties[GAMES_MEDIA_TITLE_PROPERTY]);
	}
}

static void
games_media_class_init (GamesMediaClass * klass,
                        gpointer klass_data)
{
	games_media_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesMedia_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_games_media_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_games_media_set_property;
	G_OBJECT_CLASS (klass)->finalize = games_media_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_MEDIA_TITLE_PROPERTY, games_media_properties[GAMES_MEDIA_TITLE_PROPERTY] = g_param_spec_object ("title", "title", "title", GAMES_TYPE_TITLE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
games_media_instance_init (GamesMedia * self,
                           gpointer klass)
{
	self->priv = games_media_get_instance_private (self);
}

static void
games_media_finalize (GObject * obj)
{
	GamesMedia * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_MEDIA, GamesMedia);
	_g_object_unref0 (self->priv->_title);
	self->priv->uris = (_vala_array_free (self->priv->uris, self->priv->uris_length1, (GDestroyNotify) games_uri_unref), NULL);
	G_OBJECT_CLASS (games_media_parent_class)->finalize (obj);
}

static GType
games_media_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesMediaClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_media_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesMedia), 0, (GInstanceInitFunc) games_media_instance_init, NULL };
	GType games_media_type_id;
	games_media_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesMedia", &g_define_type_info, 0);
	GamesMedia_private_offset = g_type_add_instance_private (games_media_type_id, sizeof (GamesMediaPrivate));
	return games_media_type_id;
}

GType
games_media_get_type (void)
{
	static volatile gsize games_media_type_id__once = 0;
	if (g_once_init_enter (&games_media_type_id__once)) {
		GType games_media_type_id;
		games_media_type_id = games_media_get_type_once ();
		g_once_init_leave (&games_media_type_id__once, games_media_type_id);
	}
	return games_media_type_id__once;
}

static void
_vala_games_media_get_property (GObject * object,
                                guint property_id,
                                GValue * value,
                                GParamSpec * pspec)
{
	GamesMedia * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_MEDIA, GamesMedia);
	switch (property_id) {
		case GAMES_MEDIA_TITLE_PROPERTY:
		g_value_set_object (value, games_media_get_title (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_games_media_set_property (GObject * object,
                                guint property_id,
                                const GValue * value,
                                GParamSpec * pspec)
{
	GamesMedia * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_MEDIA, GamesMedia);
	switch (property_id) {
		case GAMES_MEDIA_TITLE_PROPERTY:
		games_media_set_title (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

