/* dreamcast-uid.c generated by valac 0.36.9, the Vala compiler
 * generated from dreamcast-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_DREAMCAST_UID (games_dreamcast_uid_get_type ())
#define GAMES_DREAMCAST_UID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_DREAMCAST_UID, GamesDreamcastUid))
#define GAMES_DREAMCAST_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_DREAMCAST_UID, GamesDreamcastUidClass))
#define GAMES_IS_DREAMCAST_UID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_DREAMCAST_UID))
#define GAMES_IS_DREAMCAST_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_DREAMCAST_UID))
#define GAMES_DREAMCAST_UID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_DREAMCAST_UID, GamesDreamcastUidClass))

typedef struct _GamesDreamcastUid GamesDreamcastUid;
typedef struct _GamesDreamcastUidClass GamesDreamcastUidClass;
typedef struct _GamesDreamcastUidPrivate GamesDreamcastUidPrivate;

#define GAMES_TYPE_DREAMCAST_HEADER (games_dreamcast_header_get_type ())
#define GAMES_DREAMCAST_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_DREAMCAST_HEADER, GamesDreamcastHeader))
#define GAMES_DREAMCAST_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_DREAMCAST_HEADER, GamesDreamcastHeaderClass))
#define GAMES_IS_DREAMCAST_HEADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_DREAMCAST_HEADER))
#define GAMES_IS_DREAMCAST_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_DREAMCAST_HEADER))
#define GAMES_DREAMCAST_HEADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_DREAMCAST_HEADER, GamesDreamcastHeaderClass))

typedef struct _GamesDreamcastHeader GamesDreamcastHeader;
typedef struct _GamesDreamcastHeaderClass GamesDreamcastHeaderClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesDreamcastUid {
	GObject parent_instance;
	GamesDreamcastUidPrivate * priv;
};

struct _GamesDreamcastUidClass {
	GObjectClass parent_class;
};

struct _GamesDreamcastUidPrivate {
	GamesDreamcastHeader* header;
	gchar* uid;
};


static gpointer games_dreamcast_uid_parent_class = NULL;
static GamesUidIface * games_dreamcast_uid_games_uid_parent_iface = NULL;
static GType games_dreamcast_uid_type_id = 0;

GType games_dreamcast_uid_get_type (void) G_GNUC_CONST;
GType games_dreamcast_header_get_type (void) G_GNUC_CONST;
#define GAMES_DREAMCAST_UID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_DREAMCAST_UID, GamesDreamcastUidPrivate))
enum  {
	GAMES_DREAMCAST_UID_0_PROPERTY
};
GamesDreamcastUid* games_dreamcast_uid_new (GamesDreamcastHeader* header);
GamesDreamcastUid* games_dreamcast_uid_construct (GType object_type, GamesDreamcastHeader* header);
static gchar* games_dreamcast_uid_real_get_uid (GamesUid* base, GError** error);
gchar* games_dreamcast_header_get_product_number (GamesDreamcastHeader* self, GError** error);
gchar* games_dreamcast_header_get_areas (GamesDreamcastHeader* self, GError** error);
static void games_dreamcast_uid_finalize (GObject * obj);


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


GamesDreamcastUid* games_dreamcast_uid_construct (GType object_type, GamesDreamcastHeader* header) {
	GamesDreamcastUid * self = NULL;
	GamesDreamcastHeader* _tmp0_;
	GamesDreamcastHeader* _tmp1_;
	g_return_val_if_fail (header != NULL, NULL);
	self = (GamesDreamcastUid*) 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;
}


GamesDreamcastUid* games_dreamcast_uid_new (GamesDreamcastHeader* header) {
	return games_dreamcast_uid_construct (GAMES_TYPE_DREAMCAST_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_dreamcast_uid_real_get_uid (GamesUid* base, GError** error) {
	GamesDreamcastUid * self;
	gchar* result = NULL;
	const gchar* _tmp0_;
	gchar* product_number = NULL;
	GamesDreamcastHeader* _tmp3_;
	gchar* _tmp4_;
	gchar* areas = NULL;
	GamesDreamcastHeader* _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 = (GamesDreamcastUid*) 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_dreamcast_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_dreamcast_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 ("dreamcast-", _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_dreamcast_uid_class_init (GamesDreamcastUidClass * klass) {
	games_dreamcast_uid_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesDreamcastUidPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_dreamcast_uid_finalize;
}


static void games_dreamcast_uid_games_uid_interface_init (GamesUidIface * iface) {
	games_dreamcast_uid_games_uid_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_uid = (gchar* (*) (GamesUid *, GError**)) games_dreamcast_uid_real_get_uid;
}


static void games_dreamcast_uid_instance_init (GamesDreamcastUid * self) {
	self->priv = GAMES_DREAMCAST_UID_GET_PRIVATE (self);
}


static void games_dreamcast_uid_finalize (GObject * obj) {
	GamesDreamcastUid * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_DREAMCAST_UID, GamesDreamcastUid);
	_g_object_unref0 (self->priv->header);
	_g_free0 (self->priv->uid);
	G_OBJECT_CLASS (games_dreamcast_uid_parent_class)->finalize (obj);
}


GType games_dreamcast_uid_get_type (void) {
	return games_dreamcast_uid_type_id;
}


GType games_dreamcast_uid_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesDreamcastUidClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_dreamcast_uid_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesDreamcastUid), 0, (GInstanceInitFunc) games_dreamcast_uid_instance_init, NULL };
	static const GInterfaceInfo games_uid_info = { (GInterfaceInitFunc) games_dreamcast_uid_games_uid_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_dreamcast_uid_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesDreamcastUid", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_dreamcast_uid_type_id, GAMES_TYPE_UID, &games_uid_info);
	return games_dreamcast_uid_type_id;
}



