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

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

#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include "gnome-games.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

#define GAMES_TYPE_COLLECTION_MODEL (games_collection_model_get_type ())
#define GAMES_COLLECTION_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_COLLECTION_MODEL, GamesCollectionModel))
#define GAMES_COLLECTION_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_COLLECTION_MODEL, GamesCollectionModelClass))
#define GAMES_IS_COLLECTION_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_COLLECTION_MODEL))
#define GAMES_IS_COLLECTION_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_COLLECTION_MODEL))
#define GAMES_COLLECTION_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_COLLECTION_MODEL, GamesCollectionModelClass))

typedef struct _GamesCollectionModel GamesCollectionModel;
typedef struct _GamesCollectionModelClass GamesCollectionModelClass;
typedef struct _GamesCollectionModelPrivate GamesCollectionModelPrivate;

#define GAMES_TYPE_COLLECTION (games_collection_get_type ())
#define GAMES_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_COLLECTION, GamesCollection))
#define GAMES_IS_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_COLLECTION))
#define GAMES_COLLECTION_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_COLLECTION, GamesCollectionIface))

typedef struct _GamesCollection GamesCollection;
typedef struct _GamesCollectionIface GamesCollectionIface;

#define GAMES_TYPE_GAME_MODEL (games_game_model_get_type ())
#define GAMES_GAME_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAME_MODEL, GamesGameModel))
#define GAMES_GAME_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAME_MODEL, GamesGameModelClass))
#define GAMES_IS_GAME_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAME_MODEL))
#define GAMES_IS_GAME_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAME_MODEL))
#define GAMES_GAME_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAME_MODEL, GamesGameModelClass))

typedef struct _GamesGameModel GamesGameModel;
typedef struct _GamesGameModelClass GamesGameModelClass;
typedef enum  {
	GAMES_COLLECTION_TYPE_AUTO,
	GAMES_COLLECTION_TYPE_USER,
	GAMES_COLLECTION_TYPE_PLACEHOLDER
} GamesCollectionType;

#define GAMES_TYPE_COLLECTION_TYPE (games_collection_type_get_type ())
enum  {
	GAMES_COLLECTION_MODEL_0_PROPERTY,
	GAMES_COLLECTION_MODEL_NUM_PROPERTIES
};
static GParamSpec* games_collection_model_properties[GAMES_COLLECTION_MODEL_NUM_PROPERTIES];
#define _g_sequence_free0(var) ((var == NULL) ? NULL : (var = (g_sequence_free (var), NULL)))
enum  {
	GAMES_COLLECTION_MODEL_COLLECTION_ADDED_SIGNAL,
	GAMES_COLLECTION_MODEL_COLLECTION_REMOVED_SIGNAL,
	GAMES_COLLECTION_MODEL_NUM_SIGNALS
};
static guint games_collection_model_signals[GAMES_COLLECTION_MODEL_NUM_SIGNALS] = {0};

struct _GamesCollectionModel {
	GObject parent_instance;
	GamesCollectionModelPrivate * priv;
};

struct _GamesCollectionModelClass {
	GObjectClass parent_class;
};

struct _GamesCollectionIface {
	GTypeInterface parent_iface;
	void (*load) (GamesCollection* self);
	gchar* (*get_id) (GamesCollection* self);
	gboolean (*get_hide_stars) (GamesCollection* self);
	GamesGameModel* (*get_game_model) (GamesCollection* self);
	GamesCollectionType (*get_collection_type) (GamesCollection* self);
	void (*add_games) (GamesCollection* self, GamesGame** games, gint games_length1);
	void (*remove_games) (GamesCollection* self, GamesGame** games, gint games_length1);
	void (*on_game_added) (GamesCollection* self, GamesGame* game);
	void (*on_game_removed) (GamesCollection* self, GamesGame* game);
	void (*on_game_replaced) (GamesCollection* self, GamesGame* game, GamesGame* prev_game);
	gboolean (*get_is_empty) (GamesCollection* self);
	const gchar* (*get_title) (GamesCollection* self);
};

struct _GamesCollectionModelPrivate {
	GSequence* sequence;
	gint n_collections;
};

static gint GamesCollectionModel_private_offset;
static gpointer games_collection_model_parent_class = NULL;
static GListModelInterface * games_collection_model_g_list_model_parent_iface = NULL;

VALA_EXTERN GType games_collection_model_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_game_model_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_collection_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_collection_get_type (void) G_GNUC_CONST ;
static GObject* games_collection_model_real_get_item (GListModel* base,
                                               guint position);
static GType games_collection_model_real_get_item_type (GListModel* base);
static guint games_collection_model_real_get_n_items (GListModel* base);
VALA_EXTERN void games_collection_model_add_collection (GamesCollectionModel* self,
                                            GamesCollection* collection);
VALA_EXTERN gint games_collection_compare (GamesCollection* a,
                               GamesCollection* b);
static gint _games_collection_compare_gcompare_data_func (gconstpointer a,
                                                   gconstpointer b,
                                                   gpointer self);
VALA_EXTERN void games_collection_model_remove_collection (GamesCollectionModel* self,
                                               GamesCollection* collection);
VALA_EXTERN void games_collection_model_invalidate_sort (GamesCollectionModel* self);
VALA_EXTERN GamesCollectionModel* games_collection_model_new (void);
VALA_EXTERN GamesCollectionModel* games_collection_model_construct (GType object_type);
static GObject * games_collection_model_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static void _g_object_unref0_ (gpointer var);
static void games_collection_model_finalize (GObject * obj);
static GType games_collection_model_get_type_once (void);

static inline gpointer
games_collection_model_get_instance_private (GamesCollectionModel* self)
{
	return G_STRUCT_MEMBER_P (self, GamesCollectionModel_private_offset);
}

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

static GObject*
games_collection_model_real_get_item (GListModel* base,
                                      guint position)
{
	GamesCollectionModel * self;
	GSequenceIter* iter = NULL;
	GSequence* _tmp0_;
	GSequenceIter* _tmp1_;
	gconstpointer _tmp2_;
	GObject* _tmp3_;
	GObject* result;
	self = (GamesCollectionModel*) base;
	_tmp0_ = self->priv->sequence;
	_tmp1_ = g_sequence_get_iter_at_pos (_tmp0_, (gint) position);
	iter = _tmp1_;
	_tmp2_ = g_sequence_get (iter);
	_tmp3_ = _g_object_ref0 ((GObject*) ((GamesCollection*) _tmp2_));
	result = _tmp3_;
	return result;
}

static GType
games_collection_model_real_get_item_type (GListModel* base)
{
	GamesCollectionModel * self;
	GType result;
	self = (GamesCollectionModel*) base;
	result = GAMES_TYPE_COLLECTION;
	return result;
}

static guint
games_collection_model_real_get_n_items (GListModel* base)
{
	GamesCollectionModel * self;
	guint result;
	self = (GamesCollectionModel*) base;
	result = (guint) self->priv->n_collections;
	return result;
}

static gint
_games_collection_compare_gcompare_data_func (gconstpointer a,
                                              gconstpointer b,
                                              gpointer self)
{
	gint result;
	result = games_collection_compare ((GamesCollection*) a, (GamesCollection*) b);
	return result;
}

void
games_collection_model_add_collection (GamesCollectionModel* self,
                                       GamesCollection* collection)
{
	GSequenceIter* iter = NULL;
	GSequence* _tmp0_;
	GamesCollection* _tmp1_;
	GSequenceIter* _tmp2_;
	gint _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (collection != NULL);
	_tmp0_ = self->priv->sequence;
	_tmp1_ = _g_object_ref0 (collection);
	_tmp2_ = g_sequence_insert_sorted (_tmp0_, _tmp1_, _games_collection_compare_gcompare_data_func, NULL);
	iter = _tmp2_;
	_tmp3_ = self->priv->n_collections;
	self->priv->n_collections = _tmp3_ + 1;
	g_list_model_items_changed ((GListModel*) self, (guint) g_sequence_iter_get_position (iter), (guint) 0, (guint) 1);
	g_signal_emit (self, games_collection_model_signals[GAMES_COLLECTION_MODEL_COLLECTION_ADDED_SIGNAL], 0, collection);
}

void
games_collection_model_remove_collection (GamesCollectionModel* self,
                                          GamesCollection* collection)
{
	GSequenceIter* iter = NULL;
	GSequence* _tmp0_;
	GSequenceIter* _tmp1_;
	GSequenceIter* _tmp2_;
	gint pos = 0;
	GSequenceIter* _tmp3_;
	GSequenceIter* _tmp4_;
	gint _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (collection != NULL);
	_tmp0_ = self->priv->sequence;
	_tmp1_ = g_sequence_lookup (_tmp0_, collection, _games_collection_compare_gcompare_data_func, NULL);
	iter = _tmp1_;
	_tmp2_ = iter;
	if (_tmp2_ == NULL) {
		return;
	}
	_tmp3_ = iter;
	pos = g_sequence_iter_get_position (_tmp3_);
	_tmp4_ = iter;
	g_sequence_remove (_tmp4_);
	_tmp5_ = self->priv->n_collections;
	self->priv->n_collections = _tmp5_ - 1;
	g_list_model_items_changed ((GListModel*) self, (guint) pos, (guint) 1, (guint) 0);
	g_signal_emit (self, games_collection_model_signals[GAMES_COLLECTION_MODEL_COLLECTION_REMOVED_SIGNAL], 0, collection);
}

void
games_collection_model_invalidate_sort (GamesCollectionModel* self)
{
	GSequence* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->sequence;
	g_sequence_sort (_tmp0_, _games_collection_compare_gcompare_data_func, NULL);
	g_list_model_items_changed ((GListModel*) self, (guint) 0, (guint) self->priv->n_collections, (guint) self->priv->n_collections);
}

GamesCollectionModel*
games_collection_model_construct (GType object_type)
{
	GamesCollectionModel * self = NULL;
	self = (GamesCollectionModel*) g_object_new (object_type, NULL);
	return self;
}

GamesCollectionModel*
games_collection_model_new (void)
{
	return games_collection_model_construct (GAMES_TYPE_COLLECTION_MODEL);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static GObject *
games_collection_model_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GamesCollectionModel * self;
	GSequence* _tmp0_;
	parent_class = G_OBJECT_CLASS (games_collection_model_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_COLLECTION_MODEL, GamesCollectionModel);
	_tmp0_ = g_sequence_new (_g_object_unref0_);
	_g_sequence_free0 (self->priv->sequence);
	self->priv->sequence = _tmp0_;
	self->priv->n_collections = 0;
	return obj;
}

static void
games_collection_model_class_init (GamesCollectionModelClass * klass,
                                   gpointer klass_data)
{
	games_collection_model_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesCollectionModel_private_offset);
	G_OBJECT_CLASS (klass)->constructor = games_collection_model_constructor;
	G_OBJECT_CLASS (klass)->finalize = games_collection_model_finalize;
	games_collection_model_signals[GAMES_COLLECTION_MODEL_COLLECTION_ADDED_SIGNAL] = g_signal_new ("collection-added", GAMES_TYPE_COLLECTION_MODEL, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GAMES_TYPE_COLLECTION);
	games_collection_model_signals[GAMES_COLLECTION_MODEL_COLLECTION_REMOVED_SIGNAL] = g_signal_new ("collection-removed", GAMES_TYPE_COLLECTION_MODEL, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GAMES_TYPE_COLLECTION);
}

static void
games_collection_model_g_list_model_interface_init (GListModelInterface * iface,
                                                    gpointer iface_data)
{
	games_collection_model_g_list_model_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_item = (GObject* (*) (GListModel*, guint)) games_collection_model_real_get_item;
	iface->get_item_type = (GType (*) (GListModel*)) games_collection_model_real_get_item_type;
	iface->get_n_items = (guint (*) (GListModel*)) games_collection_model_real_get_n_items;
}

static void
games_collection_model_instance_init (GamesCollectionModel * self,
                                      gpointer klass)
{
	self->priv = games_collection_model_get_instance_private (self);
}

static void
games_collection_model_finalize (GObject * obj)
{
	GamesCollectionModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_COLLECTION_MODEL, GamesCollectionModel);
	_g_sequence_free0 (self->priv->sequence);
	G_OBJECT_CLASS (games_collection_model_parent_class)->finalize (obj);
}

static GType
games_collection_model_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesCollectionModelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_collection_model_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesCollectionModel), 0, (GInstanceInitFunc) games_collection_model_instance_init, NULL };
	static const GInterfaceInfo g_list_model_info = { (GInterfaceInitFunc) games_collection_model_g_list_model_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType games_collection_model_type_id;
	games_collection_model_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesCollectionModel", &g_define_type_info, 0);
	g_type_add_interface_static (games_collection_model_type_id, g_list_model_get_type (), &g_list_model_info);
	GamesCollectionModel_private_offset = g_type_add_instance_private (games_collection_model_type_id, sizeof (GamesCollectionModelPrivate));
	return games_collection_model_type_id;
}

GType
games_collection_model_get_type (void)
{
	static volatile gsize games_collection_model_type_id__once = 0;
	if (g_once_init_enter (&games_collection_model_type_id__once)) {
		GType games_collection_model_type_id;
		games_collection_model_type_id = games_collection_model_get_type_once ();
		g_once_init_leave (&games_collection_model_type_id__once, games_collection_model_type_id);
	}
	return games_collection_model_type_id__once;
}

