/* imap-root-parameters.c generated by valac 0.56.3, the Vala compiler
 * generated from imap-root-parameters.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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>

enum  {
	GEARY_IMAP_ROOT_PARAMETERS_0_PROPERTY,
	GEARY_IMAP_ROOT_PARAMETERS_NUM_PROPERTIES
};
static GParamSpec* geary_imap_root_parameters_properties[GEARY_IMAP_ROOT_PARAMETERS_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gpointer geary_imap_root_parameters_parent_class = NULL;

static gchar* geary_imap_root_parameters_real_to_string (GearyImapParameter* base);
static void geary_imap_root_parameters_real_serialize (GearyImapParameter* base,
                                                GearyImapSerializer* ser,
                                                GCancellable* cancellable,
                                                GError** error);
static GType geary_imap_root_parameters_get_type_once (void);

GearyImapRootParameters*
geary_imap_root_parameters_construct (GType object_type)
{
	GearyImapRootParameters * self = NULL;
	self = (GearyImapRootParameters*) geary_imap_list_parameter_construct (object_type);
	return self;
}

GearyImapRootParameters*
geary_imap_root_parameters_new (void)
{
	return geary_imap_root_parameters_construct (GEARY_IMAP_TYPE_ROOT_PARAMETERS);
}

/**
     * Moves all contained {@link Parameter} objects inside the supplied RootParameters into a
     * new RootParameters.
     *
     * The supplied root object is stripped clean by this call.
     */
GearyImapRootParameters*
geary_imap_root_parameters_construct_migrate (GType object_type,
                                              GearyImapRootParameters* root)
{
	GearyImapRootParameters * self = NULL;
	g_return_val_if_fail (GEARY_IMAP_IS_ROOT_PARAMETERS (root), NULL);
	self = (GearyImapRootParameters*) geary_imap_list_parameter_construct (object_type);
	geary_imap_list_parameter_adopt_children (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_LIST_PARAMETER, GearyImapListParameter), G_TYPE_CHECK_INSTANCE_CAST (root, GEARY_IMAP_TYPE_LIST_PARAMETER, GearyImapListParameter));
	return self;
}

GearyImapRootParameters*
geary_imap_root_parameters_new_migrate (GearyImapRootParameters* root)
{
	return geary_imap_root_parameters_construct_migrate (GEARY_IMAP_TYPE_ROOT_PARAMETERS, root);
}

/**
     * Returns null if the first parameter is not a StringParameter that resembles a Tag.
     */
GearyImapTag*
geary_imap_root_parameters_get_tag (GearyImapRootParameters* self)
{
	GearyImapStringParameter* strparam = NULL;
	GearyImapStringParameter* _tmp0_;
	GearyImapStringParameter* _tmp1_;
	GearyImapStringParameter* _tmp2_;
	GearyImapStringParameter* _tmp3_;
	GearyImapTag* _tmp4_;
	GearyImapTag* result;
	g_return_val_if_fail (GEARY_IMAP_IS_ROOT_PARAMETERS (self), NULL);
	_tmp0_ = geary_imap_list_parameter_get_if_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_LIST_PARAMETER, GearyImapListParameter), 0);
	strparam = _tmp0_;
	_tmp1_ = strparam;
	if (_tmp1_ == NULL) {
		result = NULL;
		_g_object_unref0 (strparam);
		return result;
	}
	_tmp2_ = strparam;
	if (!geary_imap_tag_is_tag (_tmp2_)) {
		result = NULL;
		_g_object_unref0 (strparam);
		return result;
	}
	_tmp3_ = strparam;
	_tmp4_ = geary_imap_tag_new_from_parameter (_tmp3_);
	result = _tmp4_;
	_g_object_unref0 (strparam);
	return result;
}

/**
     * Returns true if the first parameter is a StringParameter that resembles a Tag.
     */
gboolean
geary_imap_root_parameters_has_tag (GearyImapRootParameters* self)
{
	GearyImapStringParameter* strparam = NULL;
	GearyImapStringParameter* _tmp0_;
	GearyImapStringParameter* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GearyImapStringParameter* _tmp3_;
	gboolean result;
	g_return_val_if_fail (GEARY_IMAP_IS_ROOT_PARAMETERS (self), FALSE);
	_tmp0_ = geary_imap_list_parameter_get_if_string (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_LIST_PARAMETER, GearyImapListParameter), 0);
	strparam = _tmp0_;
	_tmp1_ = strparam;
	if (_tmp1_ == NULL) {
		result = FALSE;
		_g_object_unref0 (strparam);
		return result;
	}
	_tmp3_ = strparam;
	if (_tmp3_ != NULL) {
		GearyImapStringParameter* _tmp4_;
		_tmp4_ = strparam;
		_tmp2_ = geary_imap_tag_is_tag (_tmp4_);
	} else {
		_tmp2_ = FALSE;
	}
	result = _tmp2_;
	_g_object_unref0 (strparam);
	return result;
}

/**
     * {@inheritDoc}
     */
static gchar*
geary_imap_root_parameters_real_to_string (GearyImapParameter* base)
{
	GearyImapRootParameters * self;
	gchar* _tmp0_;
	gchar* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_ROOT_PARAMETERS, GearyImapRootParameters);
	_tmp0_ = geary_imap_list_parameter_stringize_list (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_LIST_PARAMETER, GearyImapListParameter));
	result = _tmp0_;
	return result;
}

/**
     * {@inheritDoc}
     */
static void
geary_imap_root_parameters_real_serialize (GearyImapParameter* base,
                                           GearyImapSerializer* ser,
                                           GCancellable* cancellable,
                                           GError** error)
{
	GearyImapRootParameters * self;
	GError* _inner_error0_ = NULL;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_IMAP_TYPE_ROOT_PARAMETERS, GearyImapRootParameters);
	g_return_if_fail (GEARY_IMAP_IS_SERIALIZER (ser));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	geary_imap_list_parameter_serialize_list (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_IMAP_TYPE_LIST_PARAMETER, GearyImapListParameter), ser, cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	geary_imap_serializer_push_eol (ser, cancellable, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
}

static void
geary_imap_root_parameters_class_init (GearyImapRootParametersClass * klass,
                                       gpointer klass_data)
{
	geary_imap_root_parameters_parent_class = g_type_class_peek_parent (klass);
	((GearyImapParameterClass *) klass)->to_string = (gchar* (*) (GearyImapParameter*)) geary_imap_root_parameters_real_to_string;
	((GearyImapParameterClass *) klass)->serialize = (void (*) (GearyImapParameter*, GearyImapSerializer*, GCancellable*, GError**)) geary_imap_root_parameters_real_serialize;
}

static void
geary_imap_root_parameters_instance_init (GearyImapRootParameters * self,
                                          gpointer klass)
{
}

/**
 * The base respresentation of an complete IMAP message.
 *
 * By definition, a top-level {@link ListParameter}.  A RootParameters object should never be
 * added to another list.
 *
 * @see ServerResponse
 * @see Command
 */
 G_GNUC_NO_INLINE static GType
geary_imap_root_parameters_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyImapRootParametersClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_imap_root_parameters_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyImapRootParameters), 0, (GInstanceInitFunc) geary_imap_root_parameters_instance_init, NULL };
	GType geary_imap_root_parameters_type_id;
	geary_imap_root_parameters_type_id = g_type_register_static (GEARY_IMAP_TYPE_LIST_PARAMETER, "GearyImapRootParameters", &g_define_type_info, 0);
	return geary_imap_root_parameters_type_id;
}

GType
geary_imap_root_parameters_get_type (void)
{
	static gsize geary_imap_root_parameters_type_id__once = 0;
	if (g_once_init_enter (&geary_imap_root_parameters_type_id__once)) {
		GType geary_imap_root_parameters_type_id;
		geary_imap_root_parameters_type_id = geary_imap_root_parameters_get_type_once ();
		g_once_init_leave (&geary_imap_root_parameters_type_id__once, geary_imap_root_parameters_type_id);
	}
	return geary_imap_root_parameters_type_id__once;
}

