/* Generated file (by generator) */

/*
 * SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org>
 *
 * SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "i-cal-vcard-structured.h"
#include "libical-glib-private.h"
#include "i-cal-vcard-str-array.h"

G_DEFINE_TYPE (ICalVcardStructured, i_cal_vcard_structured, I_CAL_TYPE_OBJECT)

static void i_cal_vcard_structured_class_init (G_GNUC_UNUSED ICalVcardStructuredClass *klass)
{
}

static void i_cal_vcard_structured_init (G_GNUC_UNUSED ICalVcardStructured *self)
{
}

/**
 * i_cal_vcard_structured_new_full: (skip)
 * @native: The native libical object.
 * @owner: The parent.
 *
 * Create a new libical-glib object from the native libical object and the owner.
 *
 * Returns: (transfer full): The newly create libical-glib object.
 *
 * Since: 1.0
 **/
ICalVcardStructured *
i_cal_vcard_structured_new_full (vcardstructuredtype *native, 
                                 GObject *owner)
{
    ICalVcardStructured *object;
    if (native == NULL) {
        return NULL;
    }
    
    
    object = i_cal_object_construct (I_CAL_VCARD_TYPE_STRUCTURED,
                            (gpointer) native,
                            (GDestroyNotify) g_free,
                            FALSE,
                            owner);

    return object;
}


/**
 * i_cal_vcard_structured_new:
 * @num_fields: The initial number of fields
 *
 * Creates a new #ICalVcardStructured.
 *
 * Returns: (transfer full): The newly created #ICalVcardStructured
 *
 * Since: 4.0
 *
 **/
ICalVcardStructured *
i_cal_vcard_structured_new (guint num_fields)
{
	return i_cal_vcard_structured_new_full (vcardstructured_new (num_fields), NULL);
}

/**
 * i_cal_vcard_structured_new_from_string:
 * @str: The string used to create #ICalVcardStructured
 *
 * Creates a new #ICalVcardStructured from the @str.
 *
 * Returns: (transfer full): The newly created #ICalVcardStructured from the @str.
 *
 * Since: 4.0
 *
 **/
ICalVcardStructured *
i_cal_vcard_structured_new_from_string (const gchar *str)
{
    g_return_val_if_fail (str != NULL, NULL);

	return i_cal_vcard_structured_new_full (vcardstructured_new_from_string (str), NULL);
}

/**
 * i_cal_vcard_structured_clone:
 * @self: The #ICalVcardStructured to clone
 *
 * Clones the @self.
 *
 * Returns: (transfer full): A deep copy of @self.
 *
 * Since: 4.0
 *
 **/
ICalVcardStructured *
i_cal_vcard_structured_clone (const ICalVcardStructured *self)
{
    g_return_val_if_fail (I_CAL_VCARD_IS_STRUCTURED ((ICalVcardStructured*)self), NULL);

	return i_cal_vcard_structured_new_full (vcardstructured_clone ((vcardstructuredtype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)self))), NULL);
}

/**
 * i_cal_vcard_structured_get_num_fields:
 * @self: an #ICalVcardStructured
 *
 * Gets the number of fields used by @self.
 *
 * Returns: number of fields
 *
 * Since: 4.0
 *
 **/
guint
i_cal_vcard_structured_get_num_fields (const ICalVcardStructured *self)
{
    g_return_val_if_fail(self != NULL, 0);
    return vcardstructured_num_fields(((vcardstructuredtype *)i_cal_object_get_native((ICalObject *)self)));
}

/**
 * i_cal_vcard_structured_set_num_fields:
 * @self: an #ICalVcardStructured
 * @num_fields: number of fields
 *
 * Sets how many fields the @self will hold. If @num_fields is smaller than the current number of fields,
 * the excess fields are freed.
 *
 * Since: 4.0
 *
 **/
void
i_cal_vcard_structured_set_num_fields (ICalVcardStructured *self, 
                                       guint num_fields)
{
    g_return_if_fail (I_CAL_VCARD_IS_STRUCTURED ((ICalVcardStructured*)self));

	vcardstructured_set_num_fields ((vcardstructuredtype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)self)), num_fields);
}

/**
 * i_cal_vcard_structured_get_field_at:
 * @self: an #ICalVcardStructured
 * @position: the zero-based index of the field to retrieve
 *
 * Gets the @self @position field. Returns %NULL when the item is not set or when the @position is out of
 * bounds.
 *
 * Returns: (transfer full) (nullable): a new #ICalVcardStrArray at @position
 *
 * Since: 4.0
 *
 **/
ICalVcardStrArray *
i_cal_vcard_structured_get_field_at (ICalVcardStructured *self, 
                                     guint position)
{
    vcardstrarray *field;
    g_return_val_if_fail(self != NULL, NULL);
    field = vcardstructured_field_at((vcardstructuredtype *)i_cal_object_get_native((ICalObject *)self), position);
    if (field == NULL) {
        return NULL;
    }
    return i_cal_vcard_str_array_new_full(field, NULL);
}

/**
 * i_cal_vcard_structured_set_field_at:
 * @self: an #ICalVcardStructured
 * @position: the zero-based index of the field to set
 * @field: an #ICalVcardStrArray
 *
 * Sets the @self @position field to @field. If @position is beyond the current number of fields, the number
 * of fields is extended to accommodate it. Any existing field at @position is freed before being replaced.
 *
 * Since: 4.0
 *
 **/
void
i_cal_vcard_structured_set_field_at (ICalVcardStructured *self, 
                                     guint position, 
                                     const ICalVcardStrArray *field)
{
    g_return_if_fail(self != NULL);
    g_return_if_fail(field != NULL);
    vcardstructured_set_field_at(
        (vcardstructuredtype *)i_cal_object_get_native((ICalObject *)self),
        position,
        vcardstrarray_clone((vcardstrarray *)i_cal_object_get_native((ICalObject *)field)));
}

/**
 * i_cal_vcard_structured_as_vcard_string:
 * @self: an #ICalVcardStructured
 * @is_param: whether the @self corresponds to a parameter
 *
 * Converts the @self into its string representation.
 *
 * Returns: (transfer full): The string representation of the @self.
 *
 * Since: 4.0
 *
 **/
gchar *
i_cal_vcard_structured_as_vcard_string (ICalVcardStructured *self, 
                                        gboolean is_param)
{
    g_return_val_if_fail (I_CAL_VCARD_IS_STRUCTURED ((ICalVcardStructured*)self), NULL);

	return i_cal_memory_str_to_glib (vcardstructured_as_vcard_string_r ((vcardstructuredtype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)self)), is_param));
}

/**
 * i_cal_vcard_structured_ref:
 * @self: an #ICalVcardStructured
 *
 * Increments the reference count of @self.
 *
 * Since: 4.0
 *
 **/
void
i_cal_vcard_structured_ref (ICalVcardStructured *self)
{
    g_return_if_fail (I_CAL_VCARD_IS_STRUCTURED ((ICalVcardStructured*)self));

	vcardstructured_ref ((vcardstructuredtype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)self)));
}

/**
 * i_cal_vcard_structured_unref: (skip)
 * @self: (transfer full): an #ICalVcardStructured to unref
 *
 * Decrements the reference count of @self. If this was the last reference, @self is freed.
 *
 * Since: 4.0
 *
 **/
void
i_cal_vcard_structured_unref (ICalVcardStructured *self)
{
    g_return_if_fail (I_CAL_VCARD_IS_STRUCTURED ((ICalVcardStructured*)self));

	vcardstructured_unref ((vcardstructuredtype *)i_cal_object_get_native (I_CAL_OBJECT ((ICalObject *)self)));
}
