/* app-fetch-operation.c generated by valac 0.56.19, the Vala compiler
 * generated from app-fetch-operation.vala, do not modify */

/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

#include "geary-engine.h"
#include <glib-object.h>
#include <gio/gio.h>
#include <gee.h>
#include <glib.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 GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION (geary_app_async_folder_operation_get_type ())
#define GEARY_APP_ASYNC_FOLDER_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION, GearyAppAsyncFolderOperation))
#define GEARY_APP_ASYNC_FOLDER_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION, GearyAppAsyncFolderOperationClass))
#define GEARY_APP_IS_ASYNC_FOLDER_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION))
#define GEARY_APP_IS_ASYNC_FOLDER_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION))
#define GEARY_APP_ASYNC_FOLDER_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION, GearyAppAsyncFolderOperationClass))

typedef struct _GearyAppAsyncFolderOperation GearyAppAsyncFolderOperation;
typedef struct _GearyAppAsyncFolderOperationClass GearyAppAsyncFolderOperationClass;
typedef struct _GearyAppAsyncFolderOperationPrivate GearyAppAsyncFolderOperationPrivate;

#define GEARY_APP_TYPE_FETCH_OPERATION (geary_app_fetch_operation_get_type ())
#define GEARY_APP_FETCH_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_APP_TYPE_FETCH_OPERATION, GearyAppFetchOperation))
#define GEARY_APP_FETCH_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_APP_TYPE_FETCH_OPERATION, GearyAppFetchOperationClass))
#define GEARY_APP_IS_FETCH_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_APP_TYPE_FETCH_OPERATION))
#define GEARY_APP_IS_FETCH_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_APP_TYPE_FETCH_OPERATION))
#define GEARY_APP_FETCH_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_APP_TYPE_FETCH_OPERATION, GearyAppFetchOperationClass))

typedef struct _GearyAppFetchOperation GearyAppFetchOperation;
typedef struct _GearyAppFetchOperationClass GearyAppFetchOperationClass;
typedef struct _GearyAppFetchOperationPrivate GearyAppFetchOperationPrivate;
enum  {
	GEARY_APP_FETCH_OPERATION_0_PROPERTY,
	GEARY_APP_FETCH_OPERATION_FOLDER_TYPE_PROPERTY,
	GEARY_APP_FETCH_OPERATION_NUM_PROPERTIES
};
static GParamSpec* geary_app_fetch_operation_properties[GEARY_APP_FETCH_OPERATION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _GearyAppFetchOperationExecuteAsyncData GearyAppFetchOperationExecuteAsyncData;
#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 _GearyAppAsyncFolderOperation {
	GearyBaseObject parent_instance;
	GearyAppAsyncFolderOperationPrivate * priv;
};

struct _GearyAppAsyncFolderOperationClass {
	GearyBaseObjectClass parent_class;
	GType (*get_folder_type) (GearyAppAsyncFolderOperation* self);
	void (*execute_async) (GearyAppAsyncFolderOperation* self, GearyFolder* folder, GeeCollection* ids, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	GeeCollection* (*execute_finish) (GearyAppAsyncFolderOperation* self, GAsyncResult* _res_, GError** error);
};

struct _GearyAppFetchOperation {
	GearyAppAsyncFolderOperation parent_instance;
	GearyEmail* result;
	GearyEmailField required_fields;
	GearyFolderListFlags flags;
	GearyAppFetchOperationPrivate * priv;
};

struct _GearyAppFetchOperationClass {
	GearyAppAsyncFolderOperationClass parent_class;
};

struct _GearyAppFetchOperationExecuteAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyAppFetchOperation* self;
	GearyFolder* folder;
	GeeCollection* ids;
	GCancellable* cancellable;
	GeeCollection* result;
	GearyEmail* _tmp0_;
	GearyEmailIdentifier* id;
	gpointer _tmp1_;
	GearyEmail* _tmp2_;
	GearyEmail* _tmp3_;
	GearyEmail* _tmp4_;
	GearyIterable* _tmp5_;
	GearyIterable* _tmp6_;
	GeeArrayList* _tmp7_;
	GeeCollection* _tmp8_;
	GError* _inner_error0_;
};

static gpointer geary_app_fetch_operation_parent_class = NULL;

VALA_EXTERN GType geary_app_async_folder_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_app_fetch_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_app_async_folder_operation_execute_async (GearyAppAsyncFolderOperation* self,
                                                     GearyFolder* folder,
                                                     GeeCollection* ids,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
VALA_EXTERN GeeCollection* geary_app_async_folder_operation_execute_finish (GearyAppAsyncFolderOperation* self,
                                                                GAsyncResult* _res_,
                                                                GError** error);
VALA_EXTERN GType geary_app_async_folder_operation_get_folder_type (GearyAppAsyncFolderOperation* self);
VALA_EXTERN GearyAppFetchOperation* geary_app_fetch_operation_new (GearyEmailField required_fields,
                                                       GearyFolderListFlags flags);
VALA_EXTERN GearyAppFetchOperation* geary_app_fetch_operation_construct (GType object_type,
                                                             GearyEmailField required_fields,
                                                             GearyFolderListFlags flags);
VALA_EXTERN GearyAppAsyncFolderOperation* geary_app_async_folder_operation_construct (GType object_type);
static void geary_app_fetch_operation_real_execute_async_data_free (gpointer _data);
static void geary_app_fetch_operation_real_execute_async (GearyAppAsyncFolderOperation* base,
                                                   GearyFolder* folder,
                                                   GeeCollection* ids,
                                                   GCancellable* cancellable,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
static gboolean geary_app_fetch_operation_real_execute_async_co (GearyAppFetchOperationExecuteAsyncData* _data_);
static void geary_app_fetch_operation_execute_async_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_);
static void geary_app_fetch_operation_finalize (GObject * obj);
static GType geary_app_fetch_operation_get_type_once (void);
static void _vala_geary_app_fetch_operation_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);

static GType
geary_app_fetch_operation_real_get_folder_type (GearyAppAsyncFolderOperation* base)
{
	GType result;
	GearyAppFetchOperation* self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_APP_TYPE_FETCH_OPERATION, GearyAppFetchOperation);
	result = GEARY_TYPE_FOLDER;
	return result;
}

GearyAppFetchOperation*
geary_app_fetch_operation_construct (GType object_type,
                                     GearyEmailField required_fields,
                                     GearyFolderListFlags flags)
{
	GearyAppFetchOperation * self = NULL;
	self = (GearyAppFetchOperation*) geary_app_async_folder_operation_construct (object_type);
	self->required_fields = required_fields;
	self->flags = flags;
	return self;
}

GearyAppFetchOperation*
geary_app_fetch_operation_new (GearyEmailField required_fields,
                               GearyFolderListFlags flags)
{
	return geary_app_fetch_operation_construct (GEARY_APP_TYPE_FETCH_OPERATION, required_fields, flags);
}

static void
geary_app_fetch_operation_real_execute_async_data_free (gpointer _data)
{
	GearyAppFetchOperationExecuteAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->folder);
	_g_object_unref0 (_data_->ids);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyAppFetchOperationExecuteAsyncData, _data_);
}

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

static void
geary_app_fetch_operation_real_execute_async (GearyAppAsyncFolderOperation* base,
                                              GearyFolder* folder,
                                              GeeCollection* ids,
                                              GCancellable* cancellable,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	GearyAppFetchOperation * self;
	GearyAppFetchOperationExecuteAsyncData* _data_;
	GearyAppFetchOperation* _tmp0_;
	GearyFolder* _tmp1_;
	GeeCollection* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IS_FOLDER (folder));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_APP_TYPE_FETCH_OPERATION, GearyAppFetchOperation);
	_data_ = g_slice_new0 (GearyAppFetchOperationExecuteAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_app_fetch_operation_real_execute_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (folder);
	_g_object_unref0 (_data_->folder);
	_data_->folder = _tmp1_;
	_tmp2_ = _g_object_ref0 (ids);
	_g_object_unref0 (_data_->ids);
	_data_->ids = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_app_fetch_operation_real_execute_async_co (_data_);
}

static GeeCollection*
geary_app_fetch_operation_execute_finish (GearyAppAsyncFolderOperation* base,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	GeeCollection* result;
	GearyAppFetchOperationExecuteAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
geary_app_fetch_operation_execute_async_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_)
{
	GearyAppFetchOperationExecuteAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_app_fetch_operation_real_execute_async_co (_data_);
}

static gboolean
geary_app_fetch_operation_real_execute_async_co (GearyAppFetchOperationExecuteAsyncData* _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->result;
	_vala_assert (_data_->_tmp0_ == NULL, "result == null");
	_data_->_tmp1_ = geary_collection_first (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->ids);
	_data_->id = (GearyEmailIdentifier*) _data_->_tmp1_;
	_vala_assert (_data_->id != NULL, "id != null");
	_data_->_state_ = 1;
	geary_folder_fetch_email_async (_data_->folder, _data_->id, _data_->self->required_fields, _data_->self->flags, _data_->cancellable, geary_app_fetch_operation_execute_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp3_ = geary_folder_fetch_email_finish (_data_->folder, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp2_ = _data_->_tmp3_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->id);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp4_ = _data_->_tmp2_;
	_data_->_tmp2_ = NULL;
	_g_object_unref0 (_data_->self->result);
	_data_->self->result = _data_->_tmp4_;
	_data_->_tmp5_ = geary_iterate (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->id, NULL);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = geary_iterable_to_array_list (_data_->_tmp6_, NULL, NULL, NULL);
	_data_->_tmp8_ = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp7_, GEE_TYPE_COLLECTION, GeeCollection);
	_g_object_unref0 (_data_->_tmp6_);
	_data_->result = _data_->_tmp8_;
	_g_object_unref0 (_data_->_tmp2_);
	_g_object_unref0 (_data_->id);
	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
geary_app_fetch_operation_class_init (GearyAppFetchOperationClass * klass,
                                      gpointer klass_data)
{
	geary_app_fetch_operation_parent_class = g_type_class_peek_parent (klass);
	((GearyAppAsyncFolderOperationClass *) klass)->execute_async = (void (*) (GearyAppAsyncFolderOperation*, GearyFolder*, GeeCollection*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_app_fetch_operation_real_execute_async;
	((GearyAppAsyncFolderOperationClass *) klass)->execute_finish = (GeeCollection* (*) (GearyAppAsyncFolderOperation*, GAsyncResult*, GError**)) geary_app_fetch_operation_execute_finish;
	GEARY_APP_ASYNC_FOLDER_OPERATION_CLASS (klass)->get_folder_type = (GType (*) (GearyAppAsyncFolderOperation*)) geary_app_fetch_operation_real_get_folder_type;
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_app_fetch_operation_get_property;
	G_OBJECT_CLASS (klass)->finalize = geary_app_fetch_operation_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_APP_FETCH_OPERATION_FOLDER_TYPE_PROPERTY, geary_app_fetch_operation_properties[GEARY_APP_FETCH_OPERATION_FOLDER_TYPE_PROPERTY] = g_param_spec_gtype ("folder-type", "folder-type", "folder-type", G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
geary_app_fetch_operation_instance_init (GearyAppFetchOperation * self,
                                         gpointer klass)
{
	self->result = NULL;
}

static void
geary_app_fetch_operation_finalize (GObject * obj)
{
	GearyAppFetchOperation * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_APP_TYPE_FETCH_OPERATION, GearyAppFetchOperation);
	_g_object_unref0 (self->result);
	G_OBJECT_CLASS (geary_app_fetch_operation_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_app_fetch_operation_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyAppFetchOperationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_app_fetch_operation_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyAppFetchOperation), 0, (GInstanceInitFunc) geary_app_fetch_operation_instance_init, NULL };
	GType geary_app_fetch_operation_type_id;
	geary_app_fetch_operation_type_id = g_type_register_static (GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION, "GearyAppFetchOperation", &g_define_type_info, 0);
	return geary_app_fetch_operation_type_id;
}

GType
geary_app_fetch_operation_get_type (void)
{
	static gsize geary_app_fetch_operation_type_id__once = 0;
	if (g_once_init_enter (&geary_app_fetch_operation_type_id__once)) {
		GType geary_app_fetch_operation_type_id;
		geary_app_fetch_operation_type_id = geary_app_fetch_operation_get_type_once ();
		g_once_init_leave (&geary_app_fetch_operation_type_id__once, geary_app_fetch_operation_type_id);
	}
	return geary_app_fetch_operation_type_id__once;
}

static void
_vala_geary_app_fetch_operation_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GearyAppFetchOperation * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_APP_TYPE_FETCH_OPERATION, GearyAppFetchOperation);
	switch (property_id) {
		case GEARY_APP_FETCH_OPERATION_FOLDER_TYPE_PROPERTY:
		g_value_set_gtype (value, geary_app_async_folder_operation_get_folder_type (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION, GearyAppAsyncFolderOperation)));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

