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

/*
 * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "contacts.h"
#include <gtk/gtk.h>
#include <glib-object.h>
#include <folks/folks.h>
#include <glib.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  {
	CONTACTS_PERSONA_SORTER_0_PROPERTY,
	CONTACTS_PERSONA_SORTER_NUM_PROPERTIES
};
static GParamSpec* contacts_persona_sorter_properties[CONTACTS_PERSONA_SORTER_NUM_PROPERTIES];

static gpointer contacts_persona_sorter_parent_class = NULL;

static GtkSorterOrder contacts_persona_sorter_real_get_order (GtkSorter* base);
static GtkOrdering contacts_persona_sorter_real_compare (GtkSorter* base,
                                                  GObject* item1,
                                                  GObject* item2);
static GType contacts_persona_sorter_get_type_once (void);

static GtkSorterOrder
contacts_persona_sorter_real_get_order (GtkSorter* base)
{
	ContactsPersonaSorter * self;
	GtkSorterOrder result;
	self = (ContactsPersonaSorter*) base;
	result = GTK_SORTER_ORDER_PARTIAL;
	return result;
}

static GtkOrdering
contacts_persona_sorter_real_compare (GtkSorter* base,
                                      GObject* item1,
                                      GObject* item2)
{
	ContactsPersonaSorter * self;
	FolksPersona* persona_1 = NULL;
	FolksPersona* persona_2 = NULL;
	FolksPersona* _tmp0_;
	FolksPersona* _tmp1_;
	gboolean _tmp2_ = FALSE;
	FolksPersona* _tmp3_;
	FolksPersonaStore* store_1 = NULL;
	FolksPersona* _tmp7_;
	FolksPersonaStore* _tmp8_;
	FolksPersonaStore* _tmp9_;
	FolksPersonaStore* store_2 = NULL;
	FolksPersona* _tmp10_;
	FolksPersonaStore* _tmp11_;
	FolksPersonaStore* _tmp12_;
	FolksPersonaStore* _tmp13_;
	FolksPersonaStore* _tmp14_;
	FolksPersonaStore* _tmp26_;
	gboolean _tmp27_;
	gboolean _tmp28_;
	FolksPersonaStore* _tmp29_;
	gboolean _tmp30_;
	gboolean _tmp31_;
	FolksPersonaStore* _tmp36_;
	const gchar* _tmp37_;
	const gchar* _tmp38_;
	FolksPersonaStore* _tmp39_;
	const gchar* _tmp40_;
	const gchar* _tmp41_;
	GCompareFunc _tmp46_;
	FolksPersonaStore* _tmp47_;
	const gchar* _tmp48_;
	const gchar* _tmp49_;
	FolksPersonaStore* _tmp50_;
	const gchar* _tmp51_;
	const gchar* _tmp52_;
	GtkOrdering result;
	self = (ContactsPersonaSorter*) base;
	persona_1 = G_TYPE_CHECK_INSTANCE_CAST (item1, FOLKS_TYPE_PERSONA, FolksPersona);
	persona_2 = G_TYPE_CHECK_INSTANCE_CAST (item2, FOLKS_TYPE_PERSONA, FolksPersona);
	_tmp0_ = persona_1;
	_tmp1_ = persona_2;
	if (_tmp0_ == _tmp1_) {
		result = GTK_ORDERING_EQUAL;
		return result;
	}
	_tmp3_ = persona_1;
	if (_tmp3_ == NULL) {
		_tmp2_ = TRUE;
	} else {
		FolksPersona* _tmp4_;
		_tmp4_ = persona_2;
		_tmp2_ = _tmp4_ == NULL;
	}
	if (_tmp2_) {
		GtkOrdering _tmp5_ = 0;
		FolksPersona* _tmp6_;
		_tmp6_ = persona_1;
		if (_tmp6_ == NULL) {
			_tmp5_ = GTK_ORDERING_LARGER;
		} else {
			_tmp5_ = GTK_ORDERING_SMALLER;
		}
		result = _tmp5_;
		return result;
	}
	_tmp7_ = persona_1;
	_tmp8_ = folks_persona_get_store (_tmp7_);
	_tmp9_ = _tmp8_;
	store_1 = _tmp9_;
	_tmp10_ = persona_2;
	_tmp11_ = folks_persona_get_store (_tmp10_);
	_tmp12_ = _tmp11_;
	store_2 = _tmp12_;
	_tmp13_ = store_1;
	_tmp14_ = store_2;
	if (_tmp13_ == _tmp14_) {
		FolksPersona* _tmp15_;
		GCompareFunc _tmp19_;
		FolksPersona* _tmp20_;
		const gchar* _tmp21_;
		const gchar* _tmp22_;
		FolksPersona* _tmp23_;
		const gchar* _tmp24_;
		const gchar* _tmp25_;
		_tmp15_ = persona_1;
		if (contacts_utils_persona_is_google (_tmp15_)) {
			gboolean p1_is_other = FALSE;
			FolksPersona* _tmp16_;
			FolksPersona* _tmp17_;
			_tmp16_ = persona_1;
			p1_is_other = contacts_utils_persona_is_google_other (_tmp16_);
			_tmp17_ = persona_2;
			if (p1_is_other != contacts_utils_persona_is_google_other (_tmp17_)) {
				GtkOrdering _tmp18_ = 0;
				if (p1_is_other) {
					_tmp18_ = GTK_ORDERING_LARGER;
				} else {
					_tmp18_ = GTK_ORDERING_SMALLER;
				}
				result = _tmp18_;
				return result;
			}
		}
		_tmp19_ = ((GCompareFunc) g_strcmp0);
		_tmp20_ = persona_1;
		_tmp21_ = folks_persona_get_uid (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp23_ = persona_2;
		_tmp24_ = folks_persona_get_uid (_tmp23_);
		_tmp25_ = _tmp24_;
		result = gtk_ordering_from_cmpfunc (_tmp19_ (_tmp22_, _tmp25_));
		return result;
	}
	_tmp26_ = store_1;
	_tmp27_ = folks_persona_store_get_is_primary_store (_tmp26_);
	_tmp28_ = _tmp27_;
	_tmp29_ = store_2;
	_tmp30_ = folks_persona_store_get_is_primary_store (_tmp29_);
	_tmp31_ = _tmp30_;
	if (_tmp28_ != _tmp31_) {
		GtkOrdering _tmp32_ = 0;
		FolksPersonaStore* _tmp33_;
		gboolean _tmp34_;
		gboolean _tmp35_;
		_tmp33_ = store_1;
		_tmp34_ = folks_persona_store_get_is_primary_store (_tmp33_);
		_tmp35_ = _tmp34_;
		if (_tmp35_) {
			_tmp32_ = GTK_ORDERING_SMALLER;
		} else {
			_tmp32_ = GTK_ORDERING_LARGER;
		}
		result = _tmp32_;
		return result;
	}
	_tmp36_ = store_1;
	_tmp37_ = folks_persona_store_get_type_id (_tmp36_);
	_tmp38_ = _tmp37_;
	_tmp39_ = store_2;
	_tmp40_ = folks_persona_store_get_type_id (_tmp39_);
	_tmp41_ = _tmp40_;
	if ((g_strcmp0 (_tmp38_, "eds") == 0) != (g_strcmp0 (_tmp41_, "eds") == 0)) {
		GtkOrdering _tmp42_ = 0;
		FolksPersonaStore* _tmp43_;
		const gchar* _tmp44_;
		const gchar* _tmp45_;
		_tmp43_ = store_1;
		_tmp44_ = folks_persona_store_get_type_id (_tmp43_);
		_tmp45_ = _tmp44_;
		if (g_strcmp0 (_tmp45_, "eds") == 0) {
			_tmp42_ = GTK_ORDERING_SMALLER;
		} else {
			_tmp42_ = GTK_ORDERING_LARGER;
		}
		result = _tmp42_;
		return result;
	}
	_tmp46_ = ((GCompareFunc) g_strcmp0);
	_tmp47_ = store_1;
	_tmp48_ = folks_persona_store_get_id (_tmp47_);
	_tmp49_ = _tmp48_;
	_tmp50_ = store_2;
	_tmp51_ = folks_persona_store_get_id (_tmp50_);
	_tmp52_ = _tmp51_;
	result = gtk_ordering_from_cmpfunc (_tmp46_ (_tmp49_, _tmp52_));
	return result;
}

ContactsPersonaSorter*
contacts_persona_sorter_construct (GType object_type)
{
	ContactsPersonaSorter * self = NULL;
	self = (ContactsPersonaSorter*) g_object_new (object_type, NULL);
	return self;
}

ContactsPersonaSorter*
contacts_persona_sorter_new (void)
{
	return contacts_persona_sorter_construct (CONTACTS_TYPE_PERSONA_SORTER);
}

static void
contacts_persona_sorter_class_init (ContactsPersonaSorterClass * klass,
                                    gpointer klass_data)
{
	contacts_persona_sorter_parent_class = g_type_class_peek_parent (klass);
	((GtkSorterClass *) klass)->get_order = (GtkSorterOrder (*) (GtkSorter*)) contacts_persona_sorter_real_get_order;
	((GtkSorterClass *) klass)->compare = (GtkOrdering (*) (GtkSorter*, GObject*, GObject*)) contacts_persona_sorter_real_compare;
}

static void
contacts_persona_sorter_instance_init (ContactsPersonaSorter * self,
                                       gpointer klass)
{
}

/**
 * A customer sorter that provides a consistent way of sorting
 * {@link Folks.Persona}s within the whole application.
 */
 G_GNUC_NO_INLINE static GType
contacts_persona_sorter_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsPersonaSorterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_persona_sorter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsPersonaSorter), 0, (GInstanceInitFunc) contacts_persona_sorter_instance_init, NULL };
	GType contacts_persona_sorter_type_id;
	contacts_persona_sorter_type_id = g_type_register_static (gtk_sorter_get_type (), "ContactsPersonaSorter", &g_define_type_info, 0);
	return contacts_persona_sorter_type_id;
}

GType
contacts_persona_sorter_get_type (void)
{
	static volatile gsize contacts_persona_sorter_type_id__once = 0;
	if (g_once_init_enter (&contacts_persona_sorter_type_id__once)) {
		GType contacts_persona_sorter_type_id;
		contacts_persona_sorter_type_id = contacts_persona_sorter_get_type_once ();
		g_once_init_leave (&contacts_persona_sorter_type_id__once, contacts_persona_sorter_type_id);
	}
	return contacts_persona_sorter_type_id__once;
}

