/**
 * couchdb_document_contact_im_new:
 * @uuid: A unique ID
 * @address: IM address
 * @description: Description for this IM address
 * @protocol: Protocol used for this IM address
 *
 * Returns a #CouchdbStructField representing the given IM address.
 *
 * Returns: (transfer full): A newly-created #CouchdbStructField representing
 * the given IM address information.
 */
CouchdbStructField *
couchdb_document_contact_im_new (const char *uuid,
				 const char *address,
				 const char *description,
				 const char *protocol)
{
	CouchdbStructField *sf;

	sf = couchdb_struct_field_new_from_json_object (json_object_new ());
	if (uuid != NULL)
		couchdb_struct_field_set_uuid (sf, uuid);
	else {
		char *new_uuid = generate_uuid ();
		couchdb_struct_field_set_uuid (sf, new_uuid);
		g_free (new_uuid);
	}

	if (address != NULL)
		couchdb_document_contact_im_set_address (sf, address);
	if (description != NULL)
		couchdb_document_contact_im_set_description (sf, description);
	if (protocol != NULL)
		couchdb_document_contact_im_set_protocol (sf, protocol);

	return sf;
}
/**
 * couchdb_document_contact_address_new:
 * @uuid: A unique ID
 * @street: Street
 * @ext_street: Extra information for the street
 * @city: City
 * @state: State or region
 * @country: Country
 * @postalcode: Postal code
 * @pobox: Post Office box
 * @description: Description for thos address
 *
 * Returns a #CouchdbStructField representing the given address.
 *
 * Returns: (transfer full): A newly-created #CouchdbStructField representing
 * the given address information.
 */
CouchdbStructField *
couchdb_document_contact_address_new (const char *uuid,
				      const char *street,
				      const char *ext_street,
				      const char *city,
				      const char *state,
				      const char *country,
				      const char *postalcode,
				      const char *pobox,
				      const char *description)
{
	CouchdbStructField *sf;

	sf = couchdb_struct_field_new_from_json_object (json_object_new ());
	if (uuid != NULL)
		couchdb_struct_field_set_uuid (sf, uuid);
	else {
		char *new_uuid = generate_uuid ();
		couchdb_struct_field_set_uuid (sf, new_uuid);
		g_free (new_uuid);
	}

	if (street)
		couchdb_document_contact_address_set_street (sf, street);
	if (ext_street)
		couchdb_document_contact_address_set_ext_street (sf, ext_street);
	if (city)
		couchdb_document_contact_address_set_city (sf, city);
	if (state)
		couchdb_document_contact_address_set_state (sf, state);
	if (country)
		couchdb_document_contact_address_set_country (sf, country);
	if (postalcode)
		couchdb_document_contact_address_set_postalcode (sf, postalcode);
	if (pobox)
		couchdb_document_contact_address_set_pobox (sf, pobox);
	if (description)
		couchdb_document_contact_address_set_description (sf, description);

	return sf;
}
CouchdbStructField *
desktopcouch_document_contact_email_new (const char *uuid, const char *address, const char *description)
{
	CouchdbStructField *sf;

	sf = couchdb_struct_field_new_from_json_object (json_object_new ());
	if (uuid != NULL)
		couchdb_struct_field_set_uuid (sf, uuid);
	else {
		char *new_uuid = generate_uuid ();
		couchdb_struct_field_set_uuid (sf, new_uuid);
		g_free (new_uuid);
	}

	if (address)
		desktopcouch_document_contact_email_set_address (sf, address);
	if (description)
		desktopcouch_document_contact_email_set_description (sf, description);

	return sf;
}
/**
 * couchdb_document_contact_phone_new:
 * @uuid: A unique ID
 * @number: A phone number
 * @description: Description for this phone number
 * @priority: Priority of this phone number
 *
 * Returns a #CouchdbStructField representing the given phone number.
 *
 * Returns: (transfer full): A newly-created #CouchdbStructField representing
 * the given phone number information.
 */
CouchdbStructField *
couchdb_document_contact_phone_new (const char *uuid, const char *number, const char *description, gint priority)
{
	CouchdbStructField *sf;

	sf = couchdb_struct_field_new_from_json_object (json_object_new ());
	if (uuid != NULL)
		couchdb_struct_field_set_uuid (sf, uuid);
	else {
		char *new_uuid = generate_uuid ();
		couchdb_struct_field_set_uuid (sf, new_uuid);
		g_free (new_uuid);
	}

	if (number)
		couchdb_document_contact_phone_set_number (sf, number);
	if (description)
		couchdb_document_contact_phone_set_description (sf, description);
	couchdb_document_contact_phone_set_priority (sf, priority);

	return sf;
}
static void
foreach_object_cb (JsonObject *object,
		  const char *member_name,
		  JsonNode *member_node,
		  gpointer user_data)
{
	GSList **list = (GSList **) user_data;

	if (json_node_get_node_type (member_node) == JSON_NODE_OBJECT) {
		CouchdbStructField *sf;

		sf = couchdb_struct_field_new_from_json_object (
			json_object_ref (json_node_get_object (member_node)));
		couchdb_struct_field_set_uuid (sf, member_name);
		*list = g_slist_prepend (*list, sf);
	}
}