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

/*
 * Copyright (C) 2011 Alexander Larsson <alexl@redhat.com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "contacts.h"
#include <folks/folks.h>
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.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_UNLINK_OPERATION_0_PROPERTY,
	CONTACTS_UNLINK_OPERATION_REVERSABLE_PROPERTY,
	CONTACTS_UNLINK_OPERATION_DESCRIPTION_PROPERTY,
	CONTACTS_UNLINK_OPERATION_NUM_PROPERTIES
};
static GParamSpec* contacts_unlink_operation_properties[CONTACTS_UNLINK_OPERATION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _ContactsUnlinkOperationExecuteData ContactsUnlinkOperationExecuteData;
typedef struct _ContactsUnlinkOperationUndoData ContactsUnlinkOperationUndoData;

struct _ContactsUnlinkOperationPrivate {
	ContactsStore* store;
	FolksIndividual* individual;
	GeeHashSet* personas;
	gboolean _reversable;
	gchar* _description;
};

struct _ContactsUnlinkOperationExecuteData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ContactsUnlinkOperation* self;
	GeeIterator* _persona_it;
	FolksIndividual* _tmp0_;
	GeeSet* _tmp1_;
	GeeSet* _tmp2_;
	GeeIterator* _tmp3_;
	GeeIterator* _tmp4_;
	FolksPersona* persona;
	GeeIterator* _tmp5_;
	gpointer _tmp6_;
	GeeHashSet* _tmp7_;
	FolksPersona* _tmp8_;
	ContactsStore* _tmp9_;
	FolksIndividualAggregator* _tmp10_;
	FolksIndividualAggregator* _tmp11_;
	FolksIndividual* _tmp12_;
	GError* _inner_error0_;
};

struct _ContactsUnlinkOperationUndoData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ContactsUnlinkOperation* self;
	ContactsStore* _tmp0_;
	FolksIndividualAggregator* _tmp1_;
	FolksIndividualAggregator* _tmp2_;
	GeeHashSet* _tmp3_;
	GError* _inner_error0_;
};

static gint ContactsUnlinkOperation_private_offset;
static gpointer contacts_unlink_operation_parent_class = NULL;

static void contacts_unlink_operation_real_execute_data_free (gpointer _data);
static void contacts_unlink_operation_real_execute (ContactsOperation* base,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static gboolean contacts_unlink_operation_real_execute_co (ContactsUnlinkOperationExecuteData* _data_);
static void contacts_unlink_operation_execute_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static void contacts_unlink_operation_real__undo_data_free (gpointer _data);
static void contacts_unlink_operation_real__undo (ContactsOperation* base,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_);
static gboolean contacts_unlink_operation_real__undo_co (ContactsUnlinkOperationUndoData* _data_);
static void _contacts_unlink_operation_undo_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
static void contacts_unlink_operation_finalize (GObject * obj);
static GType contacts_unlink_operation_get_type_once (void);
static void _vala_contacts_unlink_operation_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
contacts_unlink_operation_get_instance_private (ContactsUnlinkOperation* self)
{
	return G_STRUCT_MEMBER_P (self, ContactsUnlinkOperation_private_offset);
}

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

ContactsUnlinkOperation*
contacts_unlink_operation_construct (GType object_type,
                                     ContactsStore* store,
                                     FolksIndividual* main)
{
	ContactsUnlinkOperation * self = NULL;
	FolksIndividual* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (store != NULL, NULL);
	g_return_val_if_fail (main != NULL, NULL);
	self = (ContactsUnlinkOperation*) contacts_operation_construct (object_type);
	self->priv->store = store;
	_tmp0_ = _g_object_ref0 (main);
	_g_object_unref0 (self->priv->individual);
	self->priv->individual = _tmp0_;
	_tmp1_ = g_strdup (_ ("Unlinking contacts"));
	_g_free0 (self->priv->_description);
	self->priv->_description = _tmp1_;
	return self;
}

ContactsUnlinkOperation*
contacts_unlink_operation_new (ContactsStore* store,
                               FolksIndividual* main)
{
	return contacts_unlink_operation_construct (CONTACTS_TYPE_UNLINK_OPERATION, store, main);
}

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

static void
contacts_unlink_operation_real_execute (ContactsOperation* base,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	ContactsUnlinkOperation * self;
	ContactsUnlinkOperationExecuteData* _data_;
	ContactsUnlinkOperation* _tmp0_;
	self = (ContactsUnlinkOperation*) base;
	_data_ = g_slice_new0 (ContactsUnlinkOperationExecuteData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, contacts_unlink_operation_real_execute_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	contacts_unlink_operation_real_execute_co (_data_);
}

static void
contacts_unlink_operation_execute_finish (ContactsOperation* base,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	ContactsUnlinkOperationExecuteData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
contacts_unlink_operation_execute_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	ContactsUnlinkOperationExecuteData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	contacts_unlink_operation_real_execute_co (_data_);
}

static gboolean
contacts_unlink_operation_real_execute_co (ContactsUnlinkOperationExecuteData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp0_ = _data_->self->priv->individual;
		_data_->_tmp1_ = folks_individual_get_personas (_data_->_tmp0_);
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp3_ = gee_iterable_iterator ((GeeIterable*) _data_->_tmp2_);
		_data_->_persona_it = _data_->_tmp3_;
		while (TRUE) {
			_data_->_tmp4_ = _data_->_persona_it;
			if (!gee_iterator_next (_data_->_tmp4_)) {
				break;
			}
			_data_->_tmp5_ = _data_->_persona_it;
			_data_->_tmp6_ = gee_iterator_get (_data_->_tmp5_);
			_data_->persona = (FolksPersona*) _data_->_tmp6_;
			_data_->_tmp7_ = _data_->self->priv->personas;
			_data_->_tmp8_ = _data_->persona;
			gee_abstract_collection_add ((GeeAbstractCollection*) _data_->_tmp7_, _data_->_tmp8_);
			_g_object_unref0 (_data_->persona);
		}
		_g_object_unref0 (_data_->_persona_it);
	}
	_data_->_tmp9_ = _data_->self->priv->store;
	_data_->_tmp10_ = contacts_store_get_aggregator (_data_->_tmp9_);
	_data_->_tmp11_ = _data_->_tmp10_;
	_data_->_tmp12_ = _data_->self->priv->individual;
	_data_->_state_ = 1;
	folks_individual_aggregator_unlink_individual (_data_->_tmp11_, _data_->_tmp12_, contacts_unlink_operation_execute_ready, _data_);
	return FALSE;
	_state_1:
	folks_individual_aggregator_unlink_individual_finish (_data_->_tmp11_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->self->priv->_reversable = TRUE;
	g_object_notify ((GObject*) _data_->self, "reversable");
	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;
}

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

static void
contacts_unlink_operation_real__undo (ContactsOperation* base,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_)
{
	ContactsUnlinkOperation * self;
	ContactsUnlinkOperationUndoData* _data_;
	ContactsUnlinkOperation* _tmp0_;
	self = (ContactsUnlinkOperation*) base;
	_data_ = g_slice_new0 (ContactsUnlinkOperationUndoData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, contacts_unlink_operation_real__undo_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	contacts_unlink_operation_real__undo_co (_data_);
}

static void
_contacts_unlink_operation_undo_finish (ContactsOperation* base,
                                        GAsyncResult* _res_,
                                        GError** error)
{
	ContactsUnlinkOperationUndoData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
_contacts_unlink_operation_undo_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	ContactsUnlinkOperationUndoData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	contacts_unlink_operation_real__undo_co (_data_);
}

static gboolean
contacts_unlink_operation_real__undo_co (ContactsUnlinkOperationUndoData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->store;
	_data_->_tmp1_ = contacts_store_get_aggregator (_data_->_tmp0_);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = _data_->self->priv->personas;
	_data_->_state_ = 1;
	folks_individual_aggregator_link_personas (_data_->_tmp2_, (GeeSet*) _data_->_tmp3_, _contacts_unlink_operation_undo_ready, _data_);
	return FALSE;
	_state_1:
	folks_individual_aggregator_link_personas_finish (_data_->_tmp2_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->self->priv->_reversable = FALSE;
	g_object_notify ((GObject*) _data_->self, "reversable");
	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;
}

static gboolean
contacts_unlink_operation_real_get_reversable (ContactsOperation* base)
{
	gboolean result;
	ContactsUnlinkOperation* self;
	self = (ContactsUnlinkOperation*) base;
	result = self->priv->_reversable;
	return result;
}

static gchar*
contacts_unlink_operation_real_get_description (ContactsOperation* base)
{
	gchar* result;
	ContactsUnlinkOperation* self;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	self = (ContactsUnlinkOperation*) base;
	_tmp0_ = self->priv->_description;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}

static void
contacts_unlink_operation_class_init (ContactsUnlinkOperationClass * klass,
                                      gpointer klass_data)
{
	contacts_unlink_operation_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ContactsUnlinkOperation_private_offset);
	((ContactsOperationClass *) klass)->execute = (void (*) (ContactsOperation*, GAsyncReadyCallback, gpointer)) contacts_unlink_operation_real_execute;
	((ContactsOperationClass *) klass)->execute_finish = (void (*) (ContactsOperation*, GAsyncResult*, GError**)) contacts_unlink_operation_execute_finish;
	((ContactsOperationClass *) klass)->_undo = (void (*) (ContactsOperation*, GAsyncReadyCallback, gpointer)) contacts_unlink_operation_real__undo;
	((ContactsOperationClass *) klass)->_undo_finish = (void (*) (ContactsOperation*, GAsyncResult*, GError**)) _contacts_unlink_operation_undo_finish;
	CONTACTS_OPERATION_CLASS (klass)->get_reversable = (gboolean (*) (ContactsOperation*)) contacts_unlink_operation_real_get_reversable;
	CONTACTS_OPERATION_CLASS (klass)->get_description = (gchar* (*) (ContactsOperation*)) contacts_unlink_operation_real_get_description;
	G_OBJECT_CLASS (klass)->get_property = _vala_contacts_unlink_operation_get_property;
	G_OBJECT_CLASS (klass)->finalize = contacts_unlink_operation_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_UNLINK_OPERATION_REVERSABLE_PROPERTY, contacts_unlink_operation_properties[CONTACTS_UNLINK_OPERATION_REVERSABLE_PROPERTY] = g_param_spec_boolean ("reversable", "reversable", "reversable", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_UNLINK_OPERATION_DESCRIPTION_PROPERTY, contacts_unlink_operation_properties[CONTACTS_UNLINK_OPERATION_DESCRIPTION_PROPERTY] = g_param_spec_string ("description", "description", "description", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
contacts_unlink_operation_instance_init (ContactsUnlinkOperation * self,
                                         gpointer klass)
{
	GeeHashSet* _tmp0_;
	self->priv = contacts_unlink_operation_get_instance_private (self);
	_tmp0_ = gee_hash_set_new (FOLKS_TYPE_PERSONA, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->personas = _tmp0_;
	self->priv->_reversable = FALSE;
}

static void
contacts_unlink_operation_finalize (GObject * obj)
{
	ContactsUnlinkOperation * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_UNLINK_OPERATION, ContactsUnlinkOperation);
	_g_object_unref0 (self->priv->individual);
	_g_object_unref0 (self->priv->personas);
	_g_free0 (self->priv->_description);
	G_OBJECT_CLASS (contacts_unlink_operation_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
contacts_unlink_operation_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ContactsUnlinkOperationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_unlink_operation_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsUnlinkOperation), 0, (GInstanceInitFunc) contacts_unlink_operation_instance_init, NULL };
	GType contacts_unlink_operation_type_id;
	contacts_unlink_operation_type_id = g_type_register_static (CONTACTS_TYPE_OPERATION, "ContactsUnlinkOperation", &g_define_type_info, 0);
	ContactsUnlinkOperation_private_offset = g_type_add_instance_private (contacts_unlink_operation_type_id, sizeof (ContactsUnlinkOperationPrivate));
	return contacts_unlink_operation_type_id;
}

GType
contacts_unlink_operation_get_type (void)
{
	static volatile gsize contacts_unlink_operation_type_id__once = 0;
	if (g_once_init_enter (&contacts_unlink_operation_type_id__once)) {
		GType contacts_unlink_operation_type_id;
		contacts_unlink_operation_type_id = contacts_unlink_operation_get_type_once ();
		g_once_init_leave (&contacts_unlink_operation_type_id__once, contacts_unlink_operation_type_id);
	}
	return contacts_unlink_operation_type_id__once;
}

static void
_vala_contacts_unlink_operation_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	ContactsUnlinkOperation * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CONTACTS_TYPE_UNLINK_OPERATION, ContactsUnlinkOperation);
	switch (property_id) {
		case CONTACTS_UNLINK_OPERATION_REVERSABLE_PROPERTY:
		g_value_set_boolean (value, contacts_operation_get_reversable ((ContactsOperation*) self));
		break;
		case CONTACTS_UNLINK_OPERATION_DESCRIPTION_PROPERTY:
		g_value_take_string (value, contacts_operation_get_description ((ContactsOperation*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

