/* asset.c generated by valac 0.56.19, the Vala compiler
 * generated from asset.vala, do not modify */

#include "protonplus_core.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <json-glib/json-glib.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_MODELS_ASSETS_ASSET_0_PROPERTY,
	PROTON_PLUS_MODELS_ASSETS_ASSET_NAME_PROPERTY,
	PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_URL_PROPERTY,
	PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_SIZE_PROPERTY,
	PROTON_PLUS_MODELS_ASSETS_ASSET_DIGEST_PROPERTY,
	PROTON_PLUS_MODELS_ASSETS_ASSET_NUM_PROPERTIES
};
static GParamSpec* proton_plus_models_assets_asset_properties[PROTON_PLUS_MODELS_ASSETS_ASSET_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

struct _ProtonPlusModelsAssetsAssetPrivate {
	gchar* _name;
	gchar* _download_url;
	gint64 _download_size;
	gchar* _digest;
};

static gint ProtonPlusModelsAssetsAsset_private_offset;
static gpointer proton_plus_models_assets_asset_parent_class = NULL;

static void proton_plus_models_assets_asset_finalize (GObject * obj);
static GType proton_plus_models_assets_asset_get_type_once (void);
static void _vala_proton_plus_models_assets_asset_get_property (GObject * object,
                                                         guint property_id,
                                                         GValue * value,
                                                         GParamSpec * pspec);
static void _vala_proton_plus_models_assets_asset_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 gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
proton_plus_models_assets_asset_get_instance_private (ProtonPlusModelsAssetsAsset* self)
{
	return G_STRUCT_MEMBER_P (self, ProtonPlusModelsAssetsAsset_private_offset);
}

ProtonPlusModelsAssetsAsset*
proton_plus_models_assets_asset_construct (GType object_type,
                                           const gchar* name,
                                           const gchar* download_url,
                                           gint64 download_size,
                                           const gchar* digest)
{
	ProtonPlusModelsAssetsAsset * self = NULL;
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (download_url != NULL, NULL);
	g_return_val_if_fail (digest != NULL, NULL);
	self = (ProtonPlusModelsAssetsAsset*) g_object_new (object_type, "name", name, "download-url", download_url, "download-size", download_size, "digest", digest, NULL);
	return self;
}

ProtonPlusModelsAssetsAsset*
proton_plus_models_assets_asset_new (const gchar* name,
                                     const gchar* download_url,
                                     gint64 download_size,
                                     const gchar* digest)
{
	return proton_plus_models_assets_asset_construct (PROTON_PLUS_MODELS_ASSETS_TYPE_ASSET, name, download_url, download_size, digest);
}

ProtonPlusModelsAssetsAsset*
proton_plus_models_assets_asset_from_download_url (const gchar* download_url,
                                                   gint64 download_size,
                                                   const gchar* digest)
{
	gchar* path = NULL;
	gchar** _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	ProtonPlusModelsAssetsAsset* _tmp8_;
	ProtonPlusModelsAssetsAsset* _tmp9_;
	ProtonPlusModelsAssetsAsset* result;
	g_return_val_if_fail (download_url != NULL, NULL);
	g_return_val_if_fail (digest != NULL, NULL);
	_tmp1_ = _tmp0_ = g_strsplit (download_url, "?", 0);
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _vala_array_length (_tmp0_);
	_tmp3_ = _tmp2_[0];
	_tmp4_ = g_strdup (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp2_ = (_vala_array_free (_tmp2_, _tmp2__length1, (GDestroyNotify) g_free), NULL);
	path = _tmp5_;
	_tmp6_ = g_path_get_basename (path);
	_tmp7_ = _tmp6_;
	_tmp8_ = proton_plus_models_assets_asset_new (_tmp7_, download_url, download_size, digest);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	result = _tmp9_;
	_g_free0 (path);
	return result;
}

JsonObject*
proton_plus_models_assets_asset_to_json (ProtonPlusModelsAssetsAsset* self,
                                         gboolean include_download_size)
{
	JsonObject* obj = NULL;
	JsonObject* _tmp0_;
	JsonObject* _tmp1_;
	const gchar* _tmp2_;
	JsonObject* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp7_;
	JsonObject* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = json_object_new ();
	obj = _tmp0_;
	_tmp1_ = obj;
	_tmp2_ = self->priv->_name;
	json_object_set_string_member (_tmp1_, "name", _tmp2_);
	_tmp3_ = obj;
	_tmp4_ = self->priv->_download_url;
	json_object_set_string_member (_tmp3_, "download_url", _tmp4_);
	if (include_download_size) {
		JsonObject* _tmp5_;
		gint64 _tmp6_;
		_tmp5_ = obj;
		_tmp6_ = self->priv->_download_size;
		json_object_set_int_member (_tmp5_, "download_size", _tmp6_);
	}
	_tmp7_ = self->priv->_digest;
	if (g_strcmp0 (_tmp7_, "") != 0) {
		JsonObject* _tmp8_;
		const gchar* _tmp9_;
		_tmp8_ = obj;
		_tmp9_ = self->priv->_digest;
		json_object_set_string_member (_tmp8_, "digest", _tmp9_);
	}
	result = obj;
	return result;
}

ProtonPlusModelsAssetsAsset*
proton_plus_models_assets_asset_from_json (JsonObject* obj)
{
	const gchar* _tmp0_ = NULL;
	gchar* download_url = NULL;
	gchar* _tmp2_;
	const gchar* _tmp3_ = NULL;
	gchar* name = NULL;
	gchar* _tmp5_;
	gboolean _tmp6_ = FALSE;
	const gchar* _tmp7_;
	gint64 _tmp9_ = 0LL;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	ProtonPlusModelsAssetsAsset* _tmp13_;
	ProtonPlusModelsAssetsAsset* result;
	g_return_val_if_fail (obj != NULL, NULL);
	if (obj == NULL) {
		result = NULL;
		return result;
	}
	if (json_object_has_member (obj, "download_url")) {
		const gchar* _tmp1_;
		_tmp1_ = json_object_get_string_member (obj, "download_url");
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = "";
	}
	_tmp2_ = g_strdup (_tmp0_);
	download_url = _tmp2_;
	if (json_object_has_member (obj, "name")) {
		const gchar* _tmp4_;
		_tmp4_ = json_object_get_string_member (obj, "name");
		_tmp3_ = _tmp4_;
	} else {
		_tmp3_ = "";
	}
	_tmp5_ = g_strdup (_tmp3_);
	name = _tmp5_;
	_tmp7_ = name;
	if (g_strcmp0 (_tmp7_, "") == 0) {
		_tmp6_ = TRUE;
	} else {
		const gchar* _tmp8_;
		_tmp8_ = download_url;
		_tmp6_ = g_strcmp0 (_tmp8_, "") == 0;
	}
	if (_tmp6_) {
		result = NULL;
		_g_free0 (name);
		_g_free0 (download_url);
		return result;
	}
	if (json_object_has_member (obj, "download_size")) {
		_tmp9_ = json_object_get_int_member (obj, "download_size");
	} else {
		_tmp9_ = (gint64) 0;
	}
	_tmp10_ = name;
	_tmp11_ = download_url;
	_tmp12_ = json_object_get_string_member_with_default (obj, "digest", "");
	_tmp13_ = proton_plus_models_assets_asset_new (_tmp10_, _tmp11_, _tmp9_, _tmp12_);
	result = _tmp13_;
	_g_free0 (name);
	_g_free0 (download_url);
	return result;
}

gboolean
proton_plus_models_assets_asset_is_archive_name (const gchar* name)
{
	gboolean result;
	g_return_val_if_fail (name != NULL, FALSE);
	result = proton_plus_utils_archive_helper_is_archive_name (name, FALSE);
	return result;
}

gboolean
proton_plus_models_assets_asset_is_archive (ProtonPlusModelsAssetsAsset* self)
{
	const gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_name;
	result = proton_plus_models_assets_asset_is_archive_name (_tmp0_);
	return result;
}

const gchar*
proton_plus_models_assets_asset_get_name (ProtonPlusModelsAssetsAsset* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_name;
	result = _tmp0_;
	return result;
}

static void
proton_plus_models_assets_asset_set_name (ProtonPlusModelsAssetsAsset* self,
                                          const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = proton_plus_models_assets_asset_get_name (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_name);
		self->priv->_name = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, proton_plus_models_assets_asset_properties[PROTON_PLUS_MODELS_ASSETS_ASSET_NAME_PROPERTY]);
	}
}

const gchar*
proton_plus_models_assets_asset_get_download_url (ProtonPlusModelsAssetsAsset* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_download_url;
	result = _tmp0_;
	return result;
}

static void
proton_plus_models_assets_asset_set_download_url (ProtonPlusModelsAssetsAsset* self,
                                                  const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = proton_plus_models_assets_asset_get_download_url (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_download_url);
		self->priv->_download_url = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, proton_plus_models_assets_asset_properties[PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_URL_PROPERTY]);
	}
}

gint64
proton_plus_models_assets_asset_get_download_size (ProtonPlusModelsAssetsAsset* self)
{
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	result = self->priv->_download_size;
	return result;
}

static void
proton_plus_models_assets_asset_set_download_size (ProtonPlusModelsAssetsAsset* self,
                                                   gint64 value)
{
	gint64 old_value;
	g_return_if_fail (self != NULL);
	old_value = proton_plus_models_assets_asset_get_download_size (self);
	if (old_value != value) {
		self->priv->_download_size = value;
		g_object_notify_by_pspec ((GObject *) self, proton_plus_models_assets_asset_properties[PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_SIZE_PROPERTY]);
	}
}

const gchar*
proton_plus_models_assets_asset_get_digest (ProtonPlusModelsAssetsAsset* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_digest;
	result = _tmp0_;
	return result;
}

static void
proton_plus_models_assets_asset_set_digest (ProtonPlusModelsAssetsAsset* self,
                                            const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = proton_plus_models_assets_asset_get_digest (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_digest);
		self->priv->_digest = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, proton_plus_models_assets_asset_properties[PROTON_PLUS_MODELS_ASSETS_ASSET_DIGEST_PROPERTY]);
	}
}

static void
proton_plus_models_assets_asset_class_init (ProtonPlusModelsAssetsAssetClass * klass,
                                            gpointer klass_data)
{
	proton_plus_models_assets_asset_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ProtonPlusModelsAssetsAsset_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_proton_plus_models_assets_asset_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_proton_plus_models_assets_asset_set_property;
	G_OBJECT_CLASS (klass)->finalize = proton_plus_models_assets_asset_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_MODELS_ASSETS_ASSET_NAME_PROPERTY, proton_plus_models_assets_asset_properties[PROTON_PLUS_MODELS_ASSETS_ASSET_NAME_PROPERTY] = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_URL_PROPERTY, proton_plus_models_assets_asset_properties[PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_URL_PROPERTY] = g_param_spec_string ("download-url", "download-url", "download-url", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_SIZE_PROPERTY, proton_plus_models_assets_asset_properties[PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_SIZE_PROPERTY] = g_param_spec_int64 ("download-size", "download-size", "download-size", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PROTON_PLUS_MODELS_ASSETS_ASSET_DIGEST_PROPERTY, proton_plus_models_assets_asset_properties[PROTON_PLUS_MODELS_ASSETS_ASSET_DIGEST_PROPERTY] = g_param_spec_string ("digest", "digest", "digest", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
proton_plus_models_assets_asset_instance_init (ProtonPlusModelsAssetsAsset * self,
                                               gpointer klass)
{
	self->priv = proton_plus_models_assets_asset_get_instance_private (self);
}

static void
proton_plus_models_assets_asset_finalize (GObject * obj)
{
	ProtonPlusModelsAssetsAsset * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_MODELS_ASSETS_TYPE_ASSET, ProtonPlusModelsAssetsAsset);
	_g_free0 (self->priv->_name);
	_g_free0 (self->priv->_download_url);
	_g_free0 (self->priv->_digest);
	G_OBJECT_CLASS (proton_plus_models_assets_asset_parent_class)->finalize (obj);
}

static GType
proton_plus_models_assets_asset_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusModelsAssetsAssetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_models_assets_asset_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusModelsAssetsAsset), 0, (GInstanceInitFunc) proton_plus_models_assets_asset_instance_init, NULL };
	GType proton_plus_models_assets_asset_type_id;
	proton_plus_models_assets_asset_type_id = g_type_register_static (G_TYPE_OBJECT, "ProtonPlusModelsAssetsAsset", &g_define_type_info, 0);
	ProtonPlusModelsAssetsAsset_private_offset = g_type_add_instance_private (proton_plus_models_assets_asset_type_id, sizeof (ProtonPlusModelsAssetsAssetPrivate));
	return proton_plus_models_assets_asset_type_id;
}

GType
proton_plus_models_assets_asset_get_type (void)
{
	static volatile gsize proton_plus_models_assets_asset_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_models_assets_asset_type_id__once)) {
		GType proton_plus_models_assets_asset_type_id;
		proton_plus_models_assets_asset_type_id = proton_plus_models_assets_asset_get_type_once ();
		g_once_init_leave (&proton_plus_models_assets_asset_type_id__once, proton_plus_models_assets_asset_type_id);
	}
	return proton_plus_models_assets_asset_type_id__once;
}

static void
_vala_proton_plus_models_assets_asset_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec)
{
	ProtonPlusModelsAssetsAsset * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PROTON_PLUS_MODELS_ASSETS_TYPE_ASSET, ProtonPlusModelsAssetsAsset);
	switch (property_id) {
		case PROTON_PLUS_MODELS_ASSETS_ASSET_NAME_PROPERTY:
		g_value_set_string (value, proton_plus_models_assets_asset_get_name (self));
		break;
		case PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_URL_PROPERTY:
		g_value_set_string (value, proton_plus_models_assets_asset_get_download_url (self));
		break;
		case PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_SIZE_PROPERTY:
		g_value_set_int64 (value, proton_plus_models_assets_asset_get_download_size (self));
		break;
		case PROTON_PLUS_MODELS_ASSETS_ASSET_DIGEST_PROPERTY:
		g_value_set_string (value, proton_plus_models_assets_asset_get_digest (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_proton_plus_models_assets_asset_set_property (GObject * object,
                                                    guint property_id,
                                                    const GValue * value,
                                                    GParamSpec * pspec)
{
	ProtonPlusModelsAssetsAsset * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PROTON_PLUS_MODELS_ASSETS_TYPE_ASSET, ProtonPlusModelsAssetsAsset);
	switch (property_id) {
		case PROTON_PLUS_MODELS_ASSETS_ASSET_NAME_PROPERTY:
		proton_plus_models_assets_asset_set_name (self, g_value_get_string (value));
		break;
		case PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_URL_PROPERTY:
		proton_plus_models_assets_asset_set_download_url (self, g_value_get_string (value));
		break;
		case PROTON_PLUS_MODELS_ASSETS_ASSET_DOWNLOAD_SIZE_PROPERTY:
		proton_plus_models_assets_asset_set_download_size (self, g_value_get_int64 (value));
		break;
		case PROTON_PLUS_MODELS_ASSETS_ASSET_DIGEST_PROPERTY:
		proton_plus_models_assets_asset_set_digest (self, g_value_get_string (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);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

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

