/* 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-geo.h"
#include "libical-glib-private.h"

G_DEFINE_TYPE (ICalVcardGeo, i_cal_vcard_geo, I_CAL_TYPE_OBJECT)

static void i_cal_vcard_geo_class_init (G_GNUC_UNUSED ICalVcardGeoClass *klass)
{
}

static void i_cal_vcard_geo_init (G_GNUC_UNUSED ICalVcardGeo *self)
{
}

/**
 * i_cal_vcard_geo_new_full: (skip)
 * @native: The native libical object.
 *
 * 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
 **/
ICalVcardGeo *
i_cal_vcard_geo_new_full (vcardgeotype native)
{
    ICalVcardGeo *object;
    vcardgeotype *clone;
    
    
    clone = g_new (vcardgeotype, 1);
    *clone = native;
    object = i_cal_object_construct (I_CAL_VCARD_TYPE_GEO,
                            (gpointer) clone,
                            (GDestroyNotify) g_free,
                            FALSE,
                            NULL);

    return object;
}


    #define GEO_KEY_URI "i-cal-vcard-geo-key-uri"
    #define GEO_KEY_COORD_LAT "i-cal-vcard-geo-key-coord-lat"
    #define GEO_KEY_COORD_LON "i-cal-vcard-geo-key-coord-lon"
	

/**
 * priv_i_cal_vcard_null_geo: (skip)
 *
 * Returns null/empty vcardgeotype structure.
 *
 * Returns: null/empty vcardgeotype structure
 *
 * Since: 1.0
 *
 **/
vcardgeotype
priv_i_cal_vcard_null_geo (void)
{
vcardgeotype geo = { 0, };
    return geo;
}

/**
 * i_cal_vcard_geo_new_uri:
 * @uri: The URI value for the GEO
 *
 * Creates a new #ICalVcardGeo holding the URI value.
 *
 * Returns: (transfer full): The newly created #ICalVcardGeo holding the URI value
 *
 * Since: 4.0
 *
 **/
ICalVcardGeo *
i_cal_vcard_geo_new_uri (const gchar *uri)
{
    vcardgeotype geo = { 0, };
    gchar *uri_copy = g_strdup(uri);
    ICalVcardGeo *obj;
    geo.uri = uri_copy;
    obj = i_cal_vcard_geo_new_full(geo);
    g_object_set_data_full(G_OBJECT(obj), GEO_KEY_URI, uri_copy, g_free);
    return obj;
}

/**
 * i_cal_vcard_geo_new_coords:
 * @lat: a latitude coordinate
 * @lon: a longitude coordinate
 *
 * Creates a new #ICalVcardGeo holding the coordinates.
 *
 * Returns: (transfer full): The newly created #ICalVcardGeo holding the coordinates
 *
 * Since: 4.0
 *
 **/
ICalVcardGeo *
i_cal_vcard_geo_new_coords (const gchar *lat, 
                            const gchar *lon)
{
    vcardgeotype geo = { 0, };
    gchar *lat_copy = g_strdup(lat), *lon_copy = g_strdup(lon);
    ICalVcardGeo *obj;
    g_strlcpy(geo.coords.lat, lat_copy, VCARD_GEO_LEN);
    g_strlcpy(geo.coords.lon, lon_copy, VCARD_GEO_LEN);
    obj = i_cal_vcard_geo_new_full(geo);
    g_object_set_data_full(G_OBJECT(obj), GEO_KEY_COORD_LAT, lat_copy, g_free);
    g_object_set_data_full(G_OBJECT(obj), GEO_KEY_COORD_LON, lon_copy, g_free);
    return obj;
}

/**
 * i_cal_vcard_geo_clone:
 * @self: The #ICalVcardGeo to clone
 *
 * Creates a new #ICalVcardGeo, copy of @self.
 *
 * Returns: (transfer full): The newly created #ICalVcardGeo, copy of @self.
 *
 * Since: 4.0
 *
 **/
ICalVcardGeo *
i_cal_vcard_geo_clone (const ICalVcardGeo *self)
{
    vcardgeotype *gt, geo;
    gchar *uri_copy = NULL, *lat_copy = NULL, *lon_copy = NULL;
    ICalVcardGeo *obj;

    g_return_val_if_fail(I_CAL_VCARD_IS_GEO((ICalVcardGeo *)self), NULL);

    gt = (vcardgeotype *)i_cal_object_get_native((ICalObject *)self);
    g_return_val_if_fail(gt != NULL, NULL);

    geo = *gt;
    if (geo.uri) {
        uri_copy = g_strdup(geo.uri);
        geo.uri = uri_copy;
    } else {
        lat_copy = g_strdup(geo.coords.lat);
        lon_copy = g_strdup(geo.coords.lon);
        g_strlcpy(geo.coords.lat, lat_copy, VCARD_GEO_LEN);
        g_strlcpy(geo.coords.lon, lon_copy, VCARD_GEO_LEN);
    }
    obj = i_cal_vcard_geo_new_full(geo);
    g_object_set_data_full(G_OBJECT(obj), GEO_KEY_URI, uri_copy, g_free);
    g_object_set_data_full(G_OBJECT(obj), GEO_KEY_COORD_LAT, lat_copy, g_free);
    g_object_set_data_full(G_OBJECT(obj), GEO_KEY_COORD_LON, lon_copy, g_free);
    return obj;
}

/**
 * i_cal_vcard_geo_get_uri:
 * @self: an #ICalVcardGeo
 *
 * Gets the URI value of the @self. It can return %NULL when not set or when the @self is not of type URI.
 *
 * Returns: (nullable): a URI
 *
 * Since: 4.0
 *
 **/
const gchar *
i_cal_vcard_geo_get_uri (const ICalVcardGeo *self)
{
    g_return_val_if_fail(I_CAL_VCARD_IS_GEO((ICalVcardGeo *)self), NULL);
    return ((vcardgeotype *)i_cal_object_get_native((ICalObject *)self))->uri;
}

/**
 * i_cal_vcard_geo_set_uri:
 * @self: an #ICalVcardGeo
 * @uri: a URI
 *
 * Sets the URI value of the @self.
 *
 * Since: 4.0
 *
 **/
void
i_cal_vcard_geo_set_uri (ICalVcardGeo *self, 
                         const gchar *uri)
{
    vcardgeotype *geo;
    gchar *uri_copy;
    g_return_if_fail(I_CAL_VCARD_IS_GEO(self));
    g_return_if_fail(uri != NULL);
    geo = ((vcardgeotype *)i_cal_object_get_native((ICalObject *)self));
    uri_copy = g_strdup(uri);
    geo->uri = uri_copy;
    memset(geo->coords.lat, 0, VCARD_GEO_LEN);
    memset(geo->coords.lon, 0, VCARD_GEO_LEN);
    g_object_set_data_full(G_OBJECT(self), GEO_KEY_URI, uri_copy, g_free);
    g_object_set_data_full(G_OBJECT(self), GEO_KEY_COORD_LAT, NULL, NULL);
    g_object_set_data_full(G_OBJECT(self), GEO_KEY_COORD_LON, NULL, NULL);
}

/**
 * i_cal_vcard_geo_get_coords:
 * @self: an #ICalVcardGeo
 * @out_lat: (out) (optional): a location to store latitude value, or %NULL to skip it
 * @out_lon: (out) (optional): a location to store langitude value, or %NULL to skip it
 *
 * Gets the coordinates value of the @self. It can return %NULL when not set or when the @self is not of
 * coordinates type. The returned strings are valid as long as the @self is not freed nor modified.
 *
 * Since: 4.0
 *
 **/
void
i_cal_vcard_geo_get_coords (const ICalVcardGeo *self, 
                            const gchar **out_lat, 
                            const gchar **out_lon)
{
    vcardgeotype *geo;
    g_return_if_fail(I_CAL_VCARD_IS_GEO((ICalVcardGeo *)self));
    geo = ((vcardgeotype *)i_cal_object_get_native((ICalObject *)self));
    if (out_lat) {
        *out_lat = geo->coords.lat;
    }
    if (out_lon) {
        *out_lon = geo->coords.lon;
    }
    
}

/**
 * i_cal_vcard_geo_get_coord_lat:
 * @self: an #ICalVcardGeo
 *
 * Gets the latitude coordinate of the @self. It can return %NULL when not set or when the @self is not
 * of type coordinate.
 *
 * Returns: (nullable): a latitude coordinate
 *
 * Since: 4.0
 *
 **/
const gchar *
i_cal_vcard_geo_get_coord_lat (const ICalVcardGeo *self)
{
    g_return_val_if_fail(I_CAL_VCARD_IS_GEO((ICalVcardGeo *)self), NULL);
    return ((vcardgeotype *)i_cal_object_get_native((ICalObject *)self))->coords.lat;
}

/**
 * i_cal_vcard_geo_get_coord_lon:
 * @self: an #ICalVcardGeo
 *
 * Gets the longitude coordinate of the @self. It can return %NULL when not set or when the @self is not
 * of type coordinate.
 *
 * Returns: (nullable): a longitude coordinate
 *
 * Since: 4.0
 *
 **/
const gchar *
i_cal_vcard_geo_get_coord_lon (const ICalVcardGeo *self)
{
    g_return_val_if_fail(I_CAL_VCARD_IS_GEO((ICalVcardGeo *)self), NULL);
    return ((vcardgeotype *)i_cal_object_get_native((ICalObject *)self))->coords.lon;
}

/**
 * i_cal_vcard_geo_set_coords:
 * @self: an #ICalVcardGeo
 * @lat: a latitude
 * @lon: a longitude
 *
 * Sets the coordinate value of the @self.
 *
 * Since: 4.0
 *
 **/
void
i_cal_vcard_geo_set_coords (ICalVcardGeo *self, 
                            const gchar *lat, 
                            const gchar *lon)
{
    vcardgeotype *geo;
    gchar *lat_copy, *lon_copy;
    g_return_if_fail(I_CAL_VCARD_IS_GEO(self));
    g_return_if_fail(lat != NULL);
    g_return_if_fail(lon != NULL);
    geo = ((vcardgeotype *)i_cal_object_get_native((ICalObject *)self));
    lat_copy = g_strdup(lat);
    lon_copy = g_strdup(lon);
    geo->uri = NULL;
    g_strlcpy(geo->coords.lat, lat_copy, VCARD_GEO_LEN);
    g_strlcpy(geo->coords.lon, lon_copy, VCARD_GEO_LEN);
    g_object_set_data_full(G_OBJECT(self), GEO_KEY_URI, NULL, NULL);
    g_object_set_data_full(G_OBJECT(self), GEO_KEY_COORD_LAT, lat_copy, g_free);
    g_object_set_data_full(G_OBJECT(self), GEO_KEY_COORD_LON, lon_copy, g_free);
}
