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

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

#include "contactscore.h"
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <folks/folks.h>
#include <gee.h>
#include <glib-object.h>
#include <glib/gi18n-lib.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_ROLES_CHUNK_0_PROPERTY,
	CONTACTS_ROLES_CHUNK_PROPERTY_NAME_PROPERTY,
	CONTACTS_ROLES_CHUNK_DISPLAY_NAME_PROPERTY,
	CONTACTS_ROLES_CHUNK_ICON_NAME_PROPERTY,
	CONTACTS_ROLES_CHUNK_NUM_PROPERTIES
};
static GParamSpec* contacts_roles_chunk_properties[CONTACTS_ROLES_CHUNK_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _ContactsRolesChunkSaveToPersonaData ContactsRolesChunkSaveToPersonaData;
enum  {
	CONTACTS_ORG_ROLE_0_PROPERTY,
	CONTACTS_ORG_ROLE_ROLE_PROPERTY,
	CONTACTS_ORG_ROLE_IS_EMPTY_PROPERTY,
	CONTACTS_ORG_ROLE_ICON_NAME_PROPERTY,
	CONTACTS_ORG_ROLE_NUM_PROPERTIES
};
static GParamSpec* contacts_org_role_properties[CONTACTS_ORG_ROLE_NUM_PROPERTIES];
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _ContactsRolesChunkSaveToPersonaData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ContactsRolesChunk* self;
	FolksPersona* _tmp0_;
	FolksPersona* _tmp1_;
	GeeSet* afds;
	GeeSet* _tmp2_;
	FolksPersona* _tmp3_;
	FolksPersona* _tmp4_;
	GError* _inner_error0_;
};

struct _ContactsOrgRolePrivate {
	FolksRole* _role;
};

static gpointer contacts_roles_chunk_parent_class = NULL;
static gint ContactsOrgRole_private_offset;
static gpointer contacts_org_role_parent_class = NULL;

static ContactsBinChunkChild* contacts_roles_chunk_real_create_empty_child (ContactsBinChunk* base);
static void contacts_roles_chunk_real_save_to_persona_data_free (gpointer _data);
static void contacts_roles_chunk_real_save_to_persona (ContactsChunk* base,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
static gboolean contacts_roles_chunk_real_save_to_persona_co (ContactsRolesChunkSaveToPersonaData* _data_);
static void contacts_roles_chunk_save_to_persona_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_);
static GObject * contacts_roles_chunk_constructor (GType type,
                                            guint n_construct_properties,
                                            GObjectConstructParam * construct_properties);
static GType contacts_roles_chunk_get_type_once (void);
static void _vala_contacts_roles_chunk_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec);
static void contacts_org_role_set_role (ContactsOrgRole* self,
                                 FolksRole* value);
static gint contacts_org_role_real_compare_internal (ContactsBinChunkChild* base,
                                              ContactsBinChunkChild* other);
static FolksAbstractFieldDetails* contacts_org_role_real_create_afd (ContactsBinChunkChild* base);
static ContactsBinChunkChild* contacts_org_role_real_copy (ContactsBinChunkChild* base);
static GVariant* contacts_org_role_real_to_gvariant_internal (ContactsBinChunkChild* base);
static void contacts_org_role_real_apply_gvariant (ContactsBinChunkChild* base,
                                            GVariant* variant);
static void contacts_org_role_finalize (GObject * obj);
static GType contacts_org_role_get_type_once (void);
static void _vala_contacts_org_role_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_contacts_org_role_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);

static ContactsBinChunkChild*
contacts_roles_chunk_real_create_empty_child (ContactsBinChunk* base)
{
	ContactsRolesChunk * self;
	ContactsOrgRole* _tmp0_;
	ContactsBinChunkChild* result;
	self = (ContactsRolesChunk*) base;
	_tmp0_ = contacts_org_role_new ();
	result = (ContactsBinChunkChild*) _tmp0_;
	return result;
}

static void
contacts_roles_chunk_real_save_to_persona_data_free (gpointer _data)
{
	ContactsRolesChunkSaveToPersonaData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (ContactsRolesChunkSaveToPersonaData, _data_);
}

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

static void
contacts_roles_chunk_real_save_to_persona (ContactsChunk* base,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	ContactsRolesChunk * self;
	ContactsRolesChunkSaveToPersonaData* _data_;
	ContactsRolesChunk* _tmp0_;
	self = (ContactsRolesChunk*) base;
	_data_ = g_slice_new0 (ContactsRolesChunkSaveToPersonaData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, contacts_roles_chunk_real_save_to_persona_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	contacts_roles_chunk_real_save_to_persona_co (_data_);
}

static void
contacts_roles_chunk_save_to_persona_finish (ContactsChunk* base,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	ContactsRolesChunkSaveToPersonaData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
contacts_roles_chunk_save_to_persona_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_)
{
	ContactsRolesChunkSaveToPersonaData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	contacts_roles_chunk_real_save_to_persona_co (_data_);
}

static gboolean
contacts_roles_chunk_real_save_to_persona_co (ContactsRolesChunkSaveToPersonaData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = contacts_chunk_get_persona ((ContactsChunk*) _data_->self);
	_data_->_tmp1_ = _data_->_tmp0_;
	_vala_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp1_, FOLKS_TYPE_ROLE_DETAILS), "this.persona is RoleDetails", FALSE);
	_data_->_tmp2_ = contacts_bin_chunk_get_abstract_field_details ((ContactsBinChunk*) _data_->self);
	_data_->afds = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEE_TYPE_SET, GeeSet);
	_data_->_tmp3_ = contacts_chunk_get_persona ((ContactsChunk*) _data_->self);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_state_ = 1;
	folks_role_details_change_roles (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, FOLKS_TYPE_ROLE_DETAILS, FolksRoleDetails), _data_->afds, contacts_roles_chunk_save_to_persona_ready, _data_);
	return FALSE;
	_state_1:
	folks_role_details_change_roles_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp4_, FOLKS_TYPE_ROLE_DETAILS, FolksRoleDetails), _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->afds);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	contacts_bin_chunk_update_original_elements ((ContactsBinChunk*) _data_->self);
	_g_object_unref0 (_data_->afds);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

ContactsRolesChunk*
contacts_roles_chunk_construct (GType object_type)
{
	ContactsRolesChunk * self = NULL;
	self = (ContactsRolesChunk*) contacts_bin_chunk_construct (object_type);
	return self;
}

ContactsRolesChunk*
contacts_roles_chunk_new (void)
{
	return contacts_roles_chunk_construct (CONTACTS_TYPE_ROLES_CHUNK);
}

static const gchar*
contacts_roles_chunk_real_get_property_name (ContactsChunk* base)
{
	const gchar* result;
	ContactsRolesChunk* self;
	self = (ContactsRolesChunk*) base;
	result = "roles";
	return result;
}

static const gchar*
contacts_roles_chunk_real_get_display_name (ContactsChunk* base)
{
	const gchar* result;
	ContactsRolesChunk* self;
	self = (ContactsRolesChunk*) base;
	result = _ ("Roles");
	return result;
}

static const gchar*
contacts_roles_chunk_real_get_icon_name (ContactsChunk* base)
{
	const gchar* result;
	ContactsRolesChunk* self;
	self = (ContactsRolesChunk*) base;
	result = "building-symbolic";
	return result;
}

static GObject *
contacts_roles_chunk_constructor (GType type,
                                  guint n_construct_properties,
                                  GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ContactsRolesChunk * self;
	FolksPersona* _tmp0_;
	FolksPersona* _tmp1_;
	parent_class = G_OBJECT_CLASS (contacts_roles_chunk_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_ROLES_CHUNK, ContactsRolesChunk);
	_tmp0_ = contacts_chunk_get_persona ((ContactsChunk*) self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		FolksPersona* _tmp2_;
		FolksPersona* _tmp3_;
		FolksRoleDetails* role_details = NULL;
		FolksPersona* _tmp4_;
		FolksPersona* _tmp5_;
		_tmp2_ = contacts_chunk_get_persona ((ContactsChunk*) self);
		_tmp3_ = _tmp2_;
		_vala_assert (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, FOLKS_TYPE_ROLE_DETAILS), "persona is RoleDetails");
		_tmp4_ = contacts_chunk_get_persona ((ContactsChunk*) self);
		_tmp5_ = _tmp4_;
		role_details = G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, FOLKS_TYPE_ROLE_DETAILS, FolksRoleDetails);
		{
			GeeIterator* _role_field_it = NULL;
			FolksRoleDetails* _tmp6_;
			GeeSet* _tmp7_;
			GeeSet* _tmp8_;
			GeeIterator* _tmp9_;
			_tmp6_ = role_details;
			_tmp7_ = folks_role_details_get_roles (_tmp6_);
			_tmp8_ = _tmp7_;
			_tmp9_ = gee_iterable_iterator ((GeeIterable*) _tmp8_);
			_role_field_it = _tmp9_;
			while (TRUE) {
				GeeIterator* _tmp10_;
				FolksRoleFieldDetails* role_field = NULL;
				GeeIterator* _tmp11_;
				gpointer _tmp12_;
				ContactsOrgRole* role = NULL;
				FolksRoleFieldDetails* _tmp13_;
				ContactsOrgRole* _tmp14_;
				ContactsOrgRole* _tmp15_;
				_tmp10_ = _role_field_it;
				if (!gee_iterator_next (_tmp10_)) {
					break;
				}
				_tmp11_ = _role_field_it;
				_tmp12_ = gee_iterator_get (_tmp11_);
				role_field = (FolksRoleFieldDetails*) _tmp12_;
				_tmp13_ = role_field;
				_tmp14_ = contacts_org_role_new_from_field_details (_tmp13_);
				role = _tmp14_;
				_tmp15_ = role;
				contacts_bin_chunk_add_child ((ContactsBinChunk*) self, (ContactsBinChunkChild*) _tmp15_);
				_g_object_unref0 (role);
				_g_object_unref0 (role_field);
			}
			_g_object_unref0 (_role_field_it);
		}
	}
	contacts_bin_chunk_finish_initialization ((ContactsBinChunk*) self);
	return obj;
}

static void
contacts_roles_chunk_class_init (ContactsRolesChunkClass * klass,
                                 gpointer klass_data)
{
	contacts_roles_chunk_parent_class = g_type_class_peek_parent (klass);
	((ContactsBinChunkClass *) klass)->create_empty_child = (ContactsBinChunkChild* (*) (ContactsBinChunk*)) contacts_roles_chunk_real_create_empty_child;
	((ContactsChunkClass *) klass)->save_to_persona = (void (*) (ContactsChunk*, GAsyncReadyCallback, gpointer)) contacts_roles_chunk_real_save_to_persona;
	((ContactsChunkClass *) klass)->save_to_persona_finish = (void (*) (ContactsChunk*, GAsyncResult*, GError**)) contacts_roles_chunk_save_to_persona_finish;
	CONTACTS_CHUNK_CLASS (klass)->get_property_name = (const gchar* (*) (ContactsChunk*)) contacts_roles_chunk_real_get_property_name;
	CONTACTS_CHUNK_CLASS (klass)->get_display_name = (const gchar* (*) (ContactsChunk*)) contacts_roles_chunk_real_get_display_name;
	CONTACTS_CHUNK_CLASS (klass)->get_icon_name = (const gchar* (*) (ContactsChunk*)) contacts_roles_chunk_real_get_icon_name;
	G_OBJECT_CLASS (klass)->get_property = _vala_contacts_roles_chunk_get_property;
	G_OBJECT_CLASS (klass)->constructor = contacts_roles_chunk_constructor;
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_ROLES_CHUNK_PROPERTY_NAME_PROPERTY, contacts_roles_chunk_properties[CONTACTS_ROLES_CHUNK_PROPERTY_NAME_PROPERTY] = g_param_spec_string ("property-name", "property-name", "property-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_ROLES_CHUNK_DISPLAY_NAME_PROPERTY, contacts_roles_chunk_properties[CONTACTS_ROLES_CHUNK_DISPLAY_NAME_PROPERTY] = g_param_spec_string ("display-name", "display-name", "display-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_ROLES_CHUNK_ICON_NAME_PROPERTY, contacts_roles_chunk_properties[CONTACTS_ROLES_CHUNK_ICON_NAME_PROPERTY] = g_param_spec_string ("icon-name", "icon-name", "icon-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
contacts_roles_chunk_instance_init (ContactsRolesChunk * self,
                                    gpointer klass)
{
}

/**
 * A {@link Chunk} that represents the organizations and/or roles of a contact
 * (similar to {@link Folks.RoleDetails}. Each element is a
 * {@link Contacts.OrgRole}.
 */
 G_GNUC_NO_INLINE static GType
contacts_roles_chunk_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsRolesChunkClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_roles_chunk_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsRolesChunk), 0, (GInstanceInitFunc) contacts_roles_chunk_instance_init, NULL };
	GType contacts_roles_chunk_type_id;
	contacts_roles_chunk_type_id = g_type_register_static (CONTACTS_TYPE_BIN_CHUNK, "ContactsRolesChunk", &g_define_type_info, 0);
	return contacts_roles_chunk_type_id;
}

GType
contacts_roles_chunk_get_type (void)
{
	static volatile gsize contacts_roles_chunk_type_id__once = 0;
	if (g_once_init_enter (&contacts_roles_chunk_type_id__once)) {
		GType contacts_roles_chunk_type_id;
		contacts_roles_chunk_type_id = contacts_roles_chunk_get_type_once ();
		g_once_init_leave (&contacts_roles_chunk_type_id__once, contacts_roles_chunk_type_id);
	}
	return contacts_roles_chunk_type_id__once;
}

static void
_vala_contacts_roles_chunk_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec)
{
	ContactsRolesChunk * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CONTACTS_TYPE_ROLES_CHUNK, ContactsRolesChunk);
	switch (property_id) {
		case CONTACTS_ROLES_CHUNK_PROPERTY_NAME_PROPERTY:
		g_value_set_string (value, contacts_chunk_get_property_name ((ContactsChunk*) self));
		break;
		case CONTACTS_ROLES_CHUNK_DISPLAY_NAME_PROPERTY:
		g_value_set_string (value, contacts_chunk_get_display_name ((ContactsChunk*) self));
		break;
		case CONTACTS_ROLES_CHUNK_ICON_NAME_PROPERTY:
		g_value_set_string (value, contacts_chunk_get_icon_name ((ContactsChunk*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
contacts_org_role_get_instance_private (ContactsOrgRole* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsOrgRole_private_offset);
}

ContactsOrgRole*
contacts_org_role_construct (GType object_type)
{
	ContactsOrgRole * self = NULL;
	GeeHashMultiMap* _tmp0_;
	GeeHashMultiMap* _tmp1_;
	self = (ContactsOrgRole*) contacts_bin_chunk_child_construct (object_type);
	_tmp0_ = gee_hash_multi_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_tmp1_ = _tmp0_;
	contacts_bin_chunk_child_set_parameters ((ContactsBinChunkChild*) self, (GeeMultiMap*) _tmp1_);
	_g_object_unref0 (_tmp1_);
	return self;
}

ContactsOrgRole*
contacts_org_role_new (void)
{
	return contacts_org_role_construct (CONTACTS_TYPE_ORG_ROLE);
}

ContactsOrgRole*
contacts_org_role_construct_from_field_details (GType object_type,
                                                FolksRoleFieldDetails* role_field)
{
	ContactsOrgRole * self = NULL;
	gconstpointer _tmp0_;
	gconstpointer _tmp1_;
	GeeMultiMap* _tmp2_;
	GeeMultiMap* _tmp3_;
	g_return_val_if_fail (role_field != NULL, NULL);
	self = (ContactsOrgRole*) contacts_bin_chunk_child_construct (object_type);
	_tmp0_ = folks_abstract_field_details_get_value ((FolksAbstractFieldDetails*) role_field);
	_tmp1_ = _tmp0_;
	contacts_org_role_set_role (self, (FolksRole*) _tmp1_);
	_tmp2_ = folks_abstract_field_details_get_parameters ((FolksAbstractFieldDetails*) role_field);
	_tmp3_ = _tmp2_;
	contacts_bin_chunk_child_set_parameters ((ContactsBinChunkChild*) self, _tmp3_);
	return self;
}

ContactsOrgRole*
contacts_org_role_new_from_field_details (FolksRoleFieldDetails* role_field)
{
	return contacts_org_role_construct_from_field_details (CONTACTS_TYPE_ORG_ROLE, role_field);
}

static gint
contacts_org_role_real_compare_internal (ContactsBinChunkChild* base,
                                         ContactsBinChunkChild* other)
{
	ContactsOrgRole * self;
	ContactsOrgRole* other_orgrole = NULL;
	gint orgs_cmp = 0;
	GCompareFunc _tmp0_;
	FolksRole* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	ContactsOrgRole* _tmp4_;
	FolksRole* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	GCompareFunc _tmp8_;
	FolksRole* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	ContactsOrgRole* _tmp12_;
	FolksRole* _tmp13_;
	const gchar* _tmp14_;
	const gchar* _tmp15_;
	gint result;
	self = (ContactsOrgRole*) base;
	g_return_val_if_fail (other != NULL, 0);
	_vala_return_val_if_fail (CONTACTS_IS_ORG_ROLE (other), "other is OrgRole", 0);
	other_orgrole = G_TYPE_CHECK_INSTANCE_CAST (other, CONTACTS_TYPE_ORG_ROLE, ContactsOrgRole);
	_tmp0_ = ((GCompareFunc) g_strcmp0);
	_tmp1_ = self->priv->_role;
	_tmp2_ = folks_role_get_organisation_name (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = other_orgrole;
	_tmp5_ = _tmp4_->priv->_role;
	_tmp6_ = folks_role_get_organisation_name (_tmp5_);
	_tmp7_ = _tmp6_;
	orgs_cmp = _tmp0_ (_tmp3_, _tmp7_);
	if (orgs_cmp != 0) {
		result = orgs_cmp;
		return result;
	}
	_tmp8_ = ((GCompareFunc) g_strcmp0);
	_tmp9_ = self->priv->_role;
	_tmp10_ = folks_role_get_title (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = other_orgrole;
	_tmp13_ = _tmp12_->priv->_role;
	_tmp14_ = folks_role_get_title (_tmp13_);
	_tmp15_ = _tmp14_;
	result = _tmp8_ (_tmp11_, _tmp15_);
	return result;
}

static FolksAbstractFieldDetails*
contacts_org_role_real_create_afd (ContactsBinChunkChild* base)
{
	ContactsOrgRole * self;
	gboolean _tmp0_;
	gboolean _tmp1_;
	FolksRole* _tmp2_;
	GeeMultiMap* _tmp3_;
	GeeMultiMap* _tmp4_;
	FolksRoleFieldDetails* _tmp5_;
	FolksAbstractFieldDetails* result;
	self = (ContactsOrgRole*) base;
	_tmp0_ = contacts_bin_chunk_child_get_is_empty ((ContactsBinChunkChild*) self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		result = NULL;
		return result;
	}
	_tmp2_ = self->priv->_role;
	_tmp3_ = contacts_bin_chunk_child_get_parameters ((ContactsBinChunkChild*) self);
	_tmp4_ = _tmp3_;
	_tmp5_ = folks_role_field_details_new (_tmp2_, _tmp4_);
	result = (FolksAbstractFieldDetails*) _tmp5_;
	return result;
}

static ContactsBinChunkChild*
contacts_org_role_real_copy (ContactsBinChunkChild* base)
{
	ContactsOrgRole * self;
	ContactsOrgRole* org_role = NULL;
	ContactsOrgRole* _tmp0_;
	FolksRole* _tmp1_;
	FolksRole* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	FolksRole* _tmp5_;
	FolksRole* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	FolksRole* _tmp9_;
	FolksRole* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	ContactsBinChunkChild* result;
	self = (ContactsOrgRole*) base;
	_tmp0_ = contacts_org_role_new ();
	org_role = _tmp0_;
	_tmp1_ = org_role->priv->_role;
	_tmp2_ = self->priv->_role;
	_tmp3_ = folks_role_get_organisation_name (_tmp2_);
	_tmp4_ = _tmp3_;
	folks_role_set_organisation_name (_tmp1_, _tmp4_);
	_tmp5_ = org_role->priv->_role;
	_tmp6_ = self->priv->_role;
	_tmp7_ = folks_role_get_role (_tmp6_);
	_tmp8_ = _tmp7_;
	folks_role_set_role (_tmp5_, _tmp8_);
	_tmp9_ = org_role->priv->_role;
	_tmp10_ = self->priv->_role;
	_tmp11_ = folks_role_get_title (_tmp10_);
	_tmp12_ = _tmp11_;
	folks_role_set_title (_tmp9_, _tmp12_);
	contacts_bin_chunk_child_copy_parameters ((ContactsBinChunkChild*) self, (ContactsBinChunkChild*) org_role);
	result = (ContactsBinChunkChild*) org_role;
	return result;
}

static GVariant*
contacts_org_role_real_to_gvariant_internal (ContactsBinChunkChild* base)
{
	ContactsOrgRole * self;
	FolksRole* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	FolksRole* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	GVariant* _tmp6_;
	GVariant* _tmp7_;
	GVariant* _tmp8_;
	GVariant* _tmp9_;
	GVariant* result;
	self = (ContactsOrgRole*) base;
	_tmp0_ = self->priv->_role;
	_tmp1_ = folks_role_get_organisation_name (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->_role;
	_tmp4_ = folks_role_get_title (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = contacts_bin_chunk_child_parameters_to_gvariant ((ContactsBinChunkChild*) self);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_variant_new ("(ssv)", _tmp2_, _tmp5_, _tmp7_, NULL);
	g_variant_ref_sink (_tmp8_);
	_tmp9_ = _tmp8_;
	_g_variant_unref0 (_tmp7_);
	result = _tmp9_;
	return result;
}

static void
contacts_org_role_real_apply_gvariant (ContactsBinChunkChild* base,
                                       GVariant* variant)
{
	ContactsOrgRole * self;
	const GVariantType* _tmp0_;
	GVariantType* _tmp1_;
	GVariantType* _tmp2_;
	gchar* org = NULL;
	gchar* title = NULL;
	GVariant* params_variant = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	GVariant* _tmp5_ = NULL;
	FolksRole* _tmp6_;
	FolksRole* _tmp7_;
	self = (ContactsOrgRole*) base;
	g_return_if_fail (variant != NULL);
	_tmp0_ = g_variant_get_type (variant);
	_tmp1_ = g_variant_type_new ("(ssv)");
	_tmp2_ = _tmp1_;
	_vala_return_if_fail (g_variant_type_equal (_tmp0_, _tmp2_), "variant.get_type ().equal (new VariantType (\"(ssv)\"))");
	g_variant_get (variant, "(ssv)", &_tmp3_, &_tmp4_, &_tmp5_, NULL);
	_g_free0 (org);
	org = _tmp3_;
	_g_free0 (title);
	title = _tmp4_;
	_g_variant_unref0 (params_variant);
	params_variant = _tmp5_;
	_g_variant_type_free0 (_tmp2_);
	_tmp6_ = self->priv->_role;
	folks_role_set_organisation_name (_tmp6_, org);
	_tmp7_ = self->priv->_role;
	folks_role_set_title (_tmp7_, title);
	contacts_bin_chunk_child_apply_gvariant_parameters ((ContactsBinChunkChild*) self, params_variant);
	_g_variant_unref0 (params_variant);
	_g_free0 (title);
	_g_free0 (org);
}

gchar*
contacts_org_role_to_string (ContactsOrgRole* self)
{
	FolksRole* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	FolksRole* _tmp17_;
	const gchar* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_role;
	_tmp1_ = folks_role_get_title (_tmp0_);
	_tmp2_ = _tmp1_;
	if (g_strcmp0 (_tmp2_, "") != 0) {
		FolksRole* _tmp3_;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		FolksRole* _tmp13_;
		const gchar* _tmp14_;
		const gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp3_ = self->priv->_role;
		_tmp4_ = folks_role_get_organisation_name (_tmp3_);
		_tmp5_ = _tmp4_;
		if (g_strcmp0 (_tmp5_, "") != 0) {
			FolksRole* _tmp6_;
			const gchar* _tmp7_;
			const gchar* _tmp8_;
			FolksRole* _tmp9_;
			const gchar* _tmp10_;
			const gchar* _tmp11_;
			gchar* _tmp12_;
			_tmp6_ = self->priv->_role;
			_tmp7_ = folks_role_get_title (_tmp6_);
			_tmp8_ = _tmp7_;
			_tmp9_ = self->priv->_role;
			_tmp10_ = folks_role_get_organisation_name (_tmp9_);
			_tmp11_ = _tmp10_;
			_tmp12_ = g_strdup_printf (_ ("%s at %s"), _tmp8_, _tmp11_);
			result = _tmp12_;
			return result;
		}
		_tmp13_ = self->priv->_role;
		_tmp14_ = folks_role_get_title (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = g_strdup (_tmp15_);
		result = _tmp16_;
		return result;
	}
	_tmp17_ = self->priv->_role;
	_tmp18_ = folks_role_get_organisation_name (_tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = g_strdup (_tmp19_);
	result = _tmp20_;
	return result;
}

FolksRole*
contacts_org_role_get_role (ContactsOrgRole* self)
{
	FolksRole* result;
	FolksRole* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_role;
	result = _tmp0_;
	return result;
}

static void
contacts_org_role_set_role (ContactsOrgRole* self,
                            FolksRole* value)
{
	FolksRole* old_value;
	g_return_if_fail (self != NULL);
	old_value = contacts_org_role_get_role (self);
	if (old_value != value) {
		FolksRole* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_role);
		self->priv->_role = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, contacts_org_role_properties[CONTACTS_ORG_ROLE_ROLE_PROPERTY]);
	}
}

static gboolean
contacts_org_role_real_get_is_empty (ContactsBinChunkChild* base)
{
	gboolean result;
	ContactsOrgRole* self;
	FolksRole* _tmp0_;
	self = (ContactsOrgRole*) base;
	_tmp0_ = self->priv->_role;
	result = folks_role_is_empty (_tmp0_);
	return result;
}

static const gchar*
contacts_org_role_real_get_icon_name (ContactsBinChunkChild* base)
{
	const gchar* result;
	ContactsOrgRole* self;
	self = (ContactsOrgRole*) base;
	result = "building-symbolic";
	return result;
}

static void
contacts_org_role_class_init (ContactsOrgRoleClass * klass,
                              gpointer klass_data)
{
	contacts_org_role_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsOrgRole_private_offset);
	((ContactsBinChunkChildClass *) klass)->compare_internal = (gint (*) (ContactsBinChunkChild*, ContactsBinChunkChild*)) contacts_org_role_real_compare_internal;
	((ContactsBinChunkChildClass *) klass)->create_afd = (FolksAbstractFieldDetails* (*) (ContactsBinChunkChild*)) contacts_org_role_real_create_afd;
	((ContactsBinChunkChildClass *) klass)->copy = (ContactsBinChunkChild* (*) (ContactsBinChunkChild*)) contacts_org_role_real_copy;
	((ContactsBinChunkChildClass *) klass)->to_gvariant_internal = (GVariant* (*) (ContactsBinChunkChild*)) contacts_org_role_real_to_gvariant_internal;
	((ContactsBinChunkChildClass *) klass)->apply_gvariant = (void (*) (ContactsBinChunkChild*, GVariant*)) contacts_org_role_real_apply_gvariant;
	CONTACTS_BIN_CHUNK_CHILD_CLASS (klass)->get_is_empty = (gboolean (*) (ContactsBinChunkChild*)) contacts_org_role_real_get_is_empty;
	CONTACTS_BIN_CHUNK_CHILD_CLASS (klass)->get_icon_name = (const gchar* (*) (ContactsBinChunkChild*)) contacts_org_role_real_get_icon_name;
	G_OBJECT_CLASS (klass)->get_property = _vala_contacts_org_role_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_contacts_org_role_set_property;
	G_OBJECT_CLASS (klass)->finalize = contacts_org_role_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_ORG_ROLE_ROLE_PROPERTY, contacts_org_role_properties[CONTACTS_ORG_ROLE_ROLE_PROPERTY] = g_param_spec_object ("role", "role", "role", FOLKS_TYPE_ROLE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_ORG_ROLE_IS_EMPTY_PROPERTY, contacts_org_role_properties[CONTACTS_ORG_ROLE_IS_EMPTY_PROPERTY] = g_param_spec_boolean ("is-empty", "is-empty", "is-empty", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_ORG_ROLE_ICON_NAME_PROPERTY, contacts_org_role_properties[CONTACTS_ORG_ROLE_ICON_NAME_PROPERTY] = g_param_spec_string ("icon-name", "icon-name", "icon-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
contacts_org_role_instance_init (ContactsOrgRole * self,
                                 gpointer klass)
{
	FolksRole* _tmp0_;
	self->priv = contacts_org_role_get_instance_private (self);
	_tmp0_ = folks_role_new (NULL, NULL, NULL);
	self->priv->_role = _tmp0_;
}

static void
contacts_org_role_finalize (GObject * obj)
{
	ContactsOrgRole * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_ORG_ROLE, ContactsOrgRole);
	_g_object_unref0 (self->priv->_role);
	G_OBJECT_CLASS (contacts_org_role_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
contacts_org_role_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsOrgRoleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_org_role_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsOrgRole), 0, (GInstanceInitFunc) contacts_org_role_instance_init, NULL };
	GType contacts_org_role_type_id;
	contacts_org_role_type_id = g_type_register_static (CONTACTS_TYPE_BIN_CHUNK_CHILD, "ContactsOrgRole", &g_define_type_info, 0);
	ContactsOrgRole_private_offset = g_type_add_instance_private (contacts_org_role_type_id, sizeof (ContactsOrgRolePrivate));
	return contacts_org_role_type_id;
}

GType
contacts_org_role_get_type (void)
{
	static volatile gsize contacts_org_role_type_id__once = 0;
	if (g_once_init_enter (&contacts_org_role_type_id__once)) {
		GType contacts_org_role_type_id;
		contacts_org_role_type_id = contacts_org_role_get_type_once ();
		g_once_init_leave (&contacts_org_role_type_id__once, contacts_org_role_type_id);
	}
	return contacts_org_role_type_id__once;
}

static void
_vala_contacts_org_role_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	ContactsOrgRole * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CONTACTS_TYPE_ORG_ROLE, ContactsOrgRole);
	switch (property_id) {
		case CONTACTS_ORG_ROLE_ROLE_PROPERTY:
		g_value_set_object (value, contacts_org_role_get_role (self));
		break;
		case CONTACTS_ORG_ROLE_IS_EMPTY_PROPERTY:
		g_value_set_boolean (value, contacts_bin_chunk_child_get_is_empty ((ContactsBinChunkChild*) self));
		break;
		case CONTACTS_ORG_ROLE_ICON_NAME_PROPERTY:
		g_value_set_string (value, contacts_bin_chunk_child_get_icon_name ((ContactsBinChunkChild*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_contacts_org_role_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	ContactsOrgRole * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CONTACTS_TYPE_ORG_ROLE, ContactsOrgRole);
	switch (property_id) {
		case CONTACTS_ORG_ROLE_ROLE_PROPERTY:
		contacts_org_role_set_role (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

