/* sega-saturn-uid.c generated by valac 0.36.6.6-c7bee, the Vala compiler
 * generated from sega-saturn-uid.vala, do not modify */

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

#include <glib.h>
#include <glib-object.h>
#include <libgnome-games.h>
#include <stdlib.h>
#include <string.h>


#define GAMES_TYPE_SEGA_SATURN_UID (games_sega_saturn_uid_get_type ())
#define GAMES_SEGA_SATURN_UID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_SEGA_SATURN_UID, GamesSegaSaturnUid))
#define GAMES_SEGA_SATURN_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_SEGA_SATURN_UID, GamesSegaSaturnUidClass))
#define GAMES_IS_SEGA_SATURN_UID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_SEGA_SATURN_UID))
#define GAMES_IS_SEGA_SATURN_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_SEGA_SATURN_UID))
#define GAMES_SEGA_SATURN_UID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_SEGA_SATURN_UID, GamesSegaSaturnUidClass))

typedef struct _GamesSegaSaturnUid GamesSegaSaturnUid;
typedef struct _GamesSegaSaturnUidClass GamesSegaSaturnUidClass;
typedef struct _GamesSegaSaturnUidPrivate GamesSegaSaturnUidPrivate;

#define GAMES_TYPE_SEGA_SATURN_HEADER (games_sega_saturn_header_get_type ())
#define GAMES_SEGA_SATURN_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_SEGA_SATURN_HEADER, GamesSegaSaturnHeader))
#define GAMES_SEGA_SATURN_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_SEGA_SATURN_HEADER, GamesSegaSaturnHeaderClass))
#define GAMES_IS_SEGA_SATURN_HEADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_SEGA_SATURN_HEADER))
#define GAMES_IS_SEGA_SATURN_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_SEGA_SATURN_HEADER))
#define GAMES_SEGA_SATURN_HEADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_SEGA_SATURN_HEADER, GamesSegaSaturnHeaderClass))

typedef struct _GamesSegaSaturnHeader GamesSegaSaturnHeader;
typedef struct _GamesSegaSaturnHeaderClass GamesSegaSaturnHeaderClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesSegaSaturnUid {
	GObject parent_instance;
	GamesSegaSaturnUidPrivate * priv;
};

struct _GamesSegaSaturnUidClass {
	GObjectClass parent_class;
};

struct _GamesSegaSaturnUidPrivate {
	GamesSegaSaturnHeader* header;
	gchar* uid;
};


static gpointer games_sega_saturn_uid_parent_class = NULL;
static GamesUidIface * games_sega_saturn_uid_games_uid_parent_iface = NULL;
static GType games_sega_saturn_uid_type_id = 0;

GType games_sega_saturn_uid_get_type (void) G_GNUC_CONST;
GType games_sega_saturn_header_get_type (void) G_GNUC_CONST;
#define GAMES_SEGA_SATURN_UID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_SEGA_SATURN_UID, GamesSegaSaturnUidPrivate))
enum  {
	GAMES_SEGA_SATURN_UID_0_PROPERTY
};
GamesSegaSaturnUid* games_sega_saturn_uid_new (GamesSegaSaturnHeader* header);
GamesSegaSaturnUid* games_sega_saturn_uid_construct (GType object_type, GamesSegaSaturnHeader* header);
static gchar* games_sega_saturn_uid_real_get_uid (GamesUid* base, GError** error);
gchar* games_sega_saturn_header_get_product_number (GamesSegaSaturnHeader* self, GError** error);
gchar* games_sega_saturn_header_get_areas (GamesSegaSaturnHeader* self, GError** error);
static void games_sega_saturn_uid_finalize (GObject * obj);


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


GamesSegaSaturnUid* games_sega_saturn_uid_construct (GType object_type, GamesSegaSaturnHeader* header) {
	GamesSegaSaturnUid * self = NULL;
	GamesSegaSaturnHeader* _tmp0_;
	GamesSegaSaturnHeader* _tmp1_;
	g_return_val_if_fail (header != NULL, NULL);
	self = (GamesSegaSaturnUid*) g_object_new (object_type, NULL);
	_tmp0_ = header;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->header);
	self->priv->header = _tmp1_;
	return self;
}


GamesSegaSaturnUid* games_sega_saturn_uid_new (GamesSegaSaturnHeader* header) {
	return games_sega_saturn_uid_construct (GAMES_TYPE_SEGA_SATURN_UID, header);
}


static const gchar* string_to_string (const gchar* self) {
	const gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}


static gchar* games_sega_saturn_uid_real_get_uid (GamesUid* base, GError** error) {
	GamesSegaSaturnUid * self;
	gchar* result = NULL;
	const gchar* _tmp0_;
	gchar* product_number = NULL;
	GamesSegaSaturnHeader* _tmp3_;
	gchar* _tmp4_;
	gchar* areas = NULL;
	GamesSegaSaturnHeader* _tmp5_;
	gchar* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	GError * _inner_error_ = NULL;
	self = (GamesSegaSaturnUid*) base;
	_tmp0_ = self->priv->uid;
	if (_tmp0_ != NULL) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = self->priv->uid;
		_tmp2_ = g_strdup (_tmp1_);
		result = _tmp2_;
		return result;
	}
	_tmp3_ = self->priv->header;
	_tmp4_ = games_sega_saturn_header_get_product_number (_tmp3_, &_inner_error_);
	product_number = _tmp4_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp5_ = self->priv->header;
	_tmp6_ = games_sega_saturn_header_get_areas (_tmp5_, &_inner_error_);
	areas = _tmp6_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_free0 (product_number);
		return NULL;
	}
	_tmp7_ = product_number;
	_tmp8_ = string_to_string (_tmp7_);
	_tmp9_ = areas;
	_tmp10_ = string_to_string (_tmp9_);
	_tmp11_ = g_strconcat ("sega-saturn-", _tmp8_, "-", _tmp10_, NULL);
	_tmp12_ = _tmp11_;
	_tmp13_ = g_utf8_strdown (_tmp12_, (gssize) -1);
	_g_free0 (self->priv->uid);
	self->priv->uid = _tmp13_;
	_g_free0 (_tmp12_);
	_tmp14_ = self->priv->uid;
	_tmp15_ = g_strdup (_tmp14_);
	result = _tmp15_;
	_g_free0 (areas);
	_g_free0 (product_number);
	return result;
}


static void games_sega_saturn_uid_class_init (GamesSegaSaturnUidClass * klass) {
	games_sega_saturn_uid_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesSegaSaturnUidPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_sega_saturn_uid_finalize;
}


static void games_sega_saturn_uid_games_uid_interface_init (GamesUidIface * iface) {
	games_sega_saturn_uid_games_uid_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_uid = (gchar* (*) (GamesUid *, GError**)) games_sega_saturn_uid_real_get_uid;
}


static void games_sega_saturn_uid_instance_init (GamesSegaSaturnUid * self) {
	self->priv = GAMES_SEGA_SATURN_UID_GET_PRIVATE (self);
}


static void games_sega_saturn_uid_finalize (GObject * obj) {
	GamesSegaSaturnUid * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_SEGA_SATURN_UID, GamesSegaSaturnUid);
	_g_object_unref0 (self->priv->header);
	_g_free0 (self->priv->uid);
	G_OBJECT_CLASS (games_sega_saturn_uid_parent_class)->finalize (obj);
}


GType games_sega_saturn_uid_get_type (void) {
	return games_sega_saturn_uid_type_id;
}


GType games_sega_saturn_uid_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesSegaSaturnUidClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_sega_saturn_uid_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesSegaSaturnUid), 0, (GInstanceInitFunc) games_sega_saturn_uid_instance_init, NULL };
	static const GInterfaceInfo games_uid_info = { (GInterfaceInitFunc) games_sega_saturn_uid_games_uid_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_sega_saturn_uid_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesSegaSaturnUid", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_sega_saturn_uid_type_id, GAMES_TYPE_UID, &games_uid_info);
	return games_sega_saturn_uid_type_id;
}



