/* imap-store-command.c generated by valac 0.56.19, the Vala compiler
 * generated from imap-store-command.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 <gee.h>
#include <gio/gio.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  {
	GEARY_IMAP_STORE_COMMAND_0_PROPERTY,
	GEARY_IMAP_STORE_COMMAND_NUM_PROPERTIES
};
static GParamSpec* geary_imap_store_command_properties[GEARY_IMAP_STORE_COMMAND_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

static gpointer geary_imap_store_command_parent_class = NULL;

static GType geary_imap_store_command_get_type_once (void);

/** Defines how the given flags are used to update message's flags. */
 G_GNUC_NO_INLINE static GType
geary_imap_store_command_mode_get_type_once (void)
{
	static const GEnumValue values[] = {{GEARY_IMAP_STORE_COMMAND_MODE_SET_FLAGS, "GEARY_IMAP_STORE_COMMAND_MODE_SET_FLAGS", "set-flags"}, {GEARY_IMAP_STORE_COMMAND_MODE_ADD_FLAGS, "GEARY_IMAP_STORE_COMMAND_MODE_ADD_FLAGS", "add-flags"}, {GEARY_IMAP_STORE_COMMAND_MODE_REMOVE_FLAGS, "GEARY_IMAP_STORE_COMMAND_MODE_REMOVE_FLAGS", "remove-flags"}, {0, NULL, NULL}};
	GType geary_imap_store_command_mode_type_id;
	geary_imap_store_command_mode_type_id = g_enum_register_static ("GearyImapStoreCommandMode", values);
	return geary_imap_store_command_mode_type_id;
}

GType
geary_imap_store_command_mode_get_type (void)
{
	static gsize geary_imap_store_command_mode_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_store_command_mode_type_id__once)) {
		GType geary_imap_store_command_mode_type_id;
		geary_imap_store_command_mode_type_id = geary_imap_store_command_mode_get_type_once ();
		g_once_init_leave (&geary_imap_store_command_mode_type_id__once, geary_imap_store_command_mode_type_id);
	}
	return geary_imap_store_command_mode_type_id__once;
}

/** Specifies optional functionality for the command. */
 G_GNUC_NO_INLINE static GType
geary_imap_store_command_options_get_type_once (void)
{
	static const GFlagsValue values[] = {{GEARY_IMAP_STORE_COMMAND_OPTIONS_NONE, "GEARY_IMAP_STORE_COMMAND_OPTIONS_NONE", "none"}, {GEARY_IMAP_STORE_COMMAND_OPTIONS_SILENT, "GEARY_IMAP_STORE_COMMAND_OPTIONS_SILENT", "silent"}, {0, NULL, NULL}};
	GType geary_imap_store_command_options_type_id;
	geary_imap_store_command_options_type_id = g_flags_register_static ("GearyImapStoreCommandOptions", values);
	return geary_imap_store_command_options_type_id;
}

GType
geary_imap_store_command_options_get_type (void)
{
	static gsize geary_imap_store_command_options_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_store_command_options_type_id__once)) {
		GType geary_imap_store_command_options_type_id;
		geary_imap_store_command_options_type_id = geary_imap_store_command_options_get_type_once ();
		g_once_init_leave (&geary_imap_store_command_options_type_id__once, geary_imap_store_command_options_type_id);
	}
	return geary_imap_store_command_options_type_id__once;
}

GearyImapStoreCommand*
geary_imap_store_command_construct (GType object_type,
                                    GearyImapMessageSet* message_set,
                                    GearyImapStoreCommandMode mode,
                                    GearyImapStoreCommandOptions options,
                                    GeeList* flag_list,
                                    GCancellable* should_send)
{
	GearyImapStoreCommand * self = NULL;
	const gchar* _tmp0_ = NULL;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GearyImapListParameter* _tmp3_;
	GearyImapListParameter* _tmp4_;
	GearyImapParameter* _tmp5_;
	GearyImapParameter* _tmp6_;
	GString* command = NULL;
	GString* _tmp7_;
	GString* _tmp10_;
	GearyImapListParameter* _tmp12_;
	GearyImapListParameter* _tmp13_;
	GString* _tmp14_;
	const gchar* _tmp15_;
	GearyImapAtomParameter* _tmp16_;
	GearyImapAtomParameter* _tmp17_;
	GearyImapListParameter* list = NULL;
	GearyImapListParameter* _tmp18_;
	GearyImapListParameter* _tmp32_;
	GearyImapListParameter* _tmp33_;
	GearyImapListParameter* _tmp34_;
	g_return_val_if_fail (GEARY_IMAP_IS_MESSAGE_SET (message_set), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (flag_list, GEE_TYPE_LIST), NULL);
	g_return_val_if_fail ((should_send == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (should_send, g_cancellable_get_type ()), NULL);
	_tmp1_ = geary_imap_message_set_get_is_uid (message_set);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		_tmp0_ = GEARY_IMAP_STORE_COMMAND_UID_NAME;
	} else {
		_tmp0_ = GEARY_IMAP_STORE_COMMAND_NAME;
	}
	self = (GearyImapStoreCommand*) geary_imap_command_construct (object_type, _tmp0_, NULL, (gint) 0, should_send);
	_tmp3_ = geary_imap_command_get_args (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
	_tmp4_ = _tmp3_;
	_tmp5_ = geary_imap_message_set_to_parameter (message_set);
	_tmp6_ = _tmp5_;
	geary_imap_list_parameter_add (_tmp4_, _tmp6_);
	_g_object_unref0 (_tmp6_);
	_tmp7_ = g_string_new ("");
	command = _tmp7_;
	switch (mode) {
		case GEARY_IMAP_STORE_COMMAND_MODE_ADD_FLAGS:
		{
			GString* _tmp8_;
			_tmp8_ = command;
			g_string_append_c (_tmp8_, '+');
			break;
		}
		case GEARY_IMAP_STORE_COMMAND_MODE_REMOVE_FLAGS:
		{
			GString* _tmp9_;
			_tmp9_ = command;
			g_string_append_c (_tmp9_, '-');
			break;
		}
		case GEARY_IMAP_STORE_COMMAND_MODE_SET_FLAGS:
		{
			break;
		}
		default:
		break;
	}
	_tmp10_ = command;
	g_string_append (_tmp10_, "FLAGS");
	if ((options & GEARY_IMAP_STORE_COMMAND_OPTIONS_SILENT) == GEARY_IMAP_STORE_COMMAND_OPTIONS_SILENT) {
		GString* _tmp11_;
		_tmp11_ = command;
		g_string_append (_tmp11_, ".SILENT");
	}
	_tmp12_ = geary_imap_command_get_args (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
	_tmp13_ = _tmp12_;
	_tmp14_ = command;
	_tmp15_ = _tmp14_->str;
	_tmp16_ = geary_imap_atom_parameter_new (_tmp15_);
	_tmp17_ = _tmp16_;
	geary_imap_list_parameter_add (_tmp13_, G_TYPE_CHECK_INSTANCE_CAST (_tmp17_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
	_g_object_unref0 (_tmp17_);
	_tmp18_ = geary_imap_list_parameter_new ();
	list = _tmp18_;
	{
		GeeList* _flag_list = NULL;
		gint _flag_size = 0;
		GeeList* _tmp19_;
		gint _tmp20_;
		gint _tmp21_;
		gint _flag_index = 0;
		_flag_list = flag_list;
		_tmp19_ = _flag_list;
		_tmp20_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp21_ = _tmp20_;
		_flag_size = _tmp21_;
		_flag_index = -1;
		while (TRUE) {
			gint _tmp22_;
			gint _tmp23_;
			GearyImapMessageFlag* flag = NULL;
			GeeList* _tmp24_;
			gpointer _tmp25_;
			GearyImapListParameter* _tmp26_;
			GearyImapMessageFlag* _tmp27_;
			const gchar* _tmp28_;
			const gchar* _tmp29_;
			GearyImapAtomParameter* _tmp30_;
			GearyImapAtomParameter* _tmp31_;
			_flag_index = _flag_index + 1;
			_tmp22_ = _flag_index;
			_tmp23_ = _flag_size;
			if (!(_tmp22_ < _tmp23_)) {
				break;
			}
			_tmp24_ = _flag_list;
			_tmp25_ = gee_list_get (_tmp24_, _flag_index);
			flag = (GearyImapMessageFlag*) _tmp25_;
			_tmp26_ = list;
			_tmp27_ = flag;
			_tmp28_ = geary_imap_flag_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp27_, GEARY_IMAP_TYPE_FLAG, GearyImapFlag));
			_tmp29_ = _tmp28_;
			_tmp30_ = geary_imap_atom_parameter_new (_tmp29_);
			_tmp31_ = _tmp30_;
			geary_imap_list_parameter_add (_tmp26_, G_TYPE_CHECK_INSTANCE_CAST (_tmp31_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
			_g_object_unref0 (_tmp31_);
			_g_object_unref0 (flag);
		}
	}
	_tmp32_ = geary_imap_command_get_args (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_COMMAND, GearyImapCommand));
	_tmp33_ = _tmp32_;
	_tmp34_ = list;
	geary_imap_list_parameter_add (_tmp33_, G_TYPE_CHECK_INSTANCE_CAST (_tmp34_, GEARY_IMAP_TYPE_PARAMETER, GearyImapParameter));
	_g_object_unref0 (list);
	_g_string_free0 (command);
	return self;
}

GearyImapStoreCommand*
geary_imap_store_command_new (GearyImapMessageSet* message_set,
                              GearyImapStoreCommandMode mode,
                              GearyImapStoreCommandOptions options,
                              GeeList* flag_list,
                              GCancellable* should_send)
{
	return geary_imap_store_command_construct (GEARY_IMAP_TYPE_STORE_COMMAND, message_set, mode, options, flag_list, should_send);
}

static void
geary_imap_store_command_class_init (GearyImapStoreCommandClass * klass,
                                     gpointer klass_data)
{
	geary_imap_store_command_parent_class = g_type_class_peek_parent (klass);
}

static void
geary_imap_store_command_instance_init (GearyImapStoreCommand * self,
                                        gpointer klass)
{
}

/**
 * The IMAP `STORE` and `UID STORE` commands.
 *
 * See [[http://tools.ietf.org/html/rfc3501#section-6.4.6]]
 *
 * @see FetchCommand
 * @see FetchedData
 */
 G_GNUC_NO_INLINE static GType
geary_imap_store_command_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapStoreCommandClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_store_command_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapStoreCommand), 0, (GInstanceInitFunc) geary_imap_store_command_instance_init, NULL };
	GType geary_imap_store_command_type_id;
	geary_imap_store_command_type_id = g_type_register_static (GEARY_IMAP_TYPE_COMMAND, "GearyImapStoreCommand", &g_define_type_info, 0);
	return geary_imap_store_command_type_id;
}

GType
geary_imap_store_command_get_type (void)
{
	static gsize geary_imap_store_command_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_store_command_type_id__once)) {
		GType geary_imap_store_command_type_id;
		geary_imap_store_command_type_id = geary_imap_store_command_get_type_once ();
		g_once_init_leave (&geary_imap_store_command_type_id__once, geary_imap_store_command_type_id);
	}
	return geary_imap_store_command_type_id__once;
}

