/* TodoistProjects.c generated by valac 0.56.19, the Vala compiler
 * generated from TodoistProjects.vala, do not modify */

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include "planify.h"
#include <libsoup/soup.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <json-glib/json-glib.h>
#include <gee.h>

#define SERVICES_TODOIST_PROJECTS_TODOIST_SYNC_URL "https://api.todoist.com/api/v1/sync"
#define SERVICES_TODOIST_PROJECTS_MIGRATE_MESSAGE _ ("Todoist has updated their API. Please reconnect your account in Prefer" \
"ences to continue syncing.")
#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  {
	SERVICES_TODOIST_PROJECTS_0_PROPERTY,
	SERVICES_TODOIST_PROJECTS_NUM_PROPERTIES
};
static GParamSpec* services_todoist_projects_properties[SERVICES_TODOIST_PROJECTS_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _http_response_unref0(var) ((var == NULL) ? NULL : (var = (http_response_unref (var), NULL)))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define __vala_JsonNode_free0(var) ((var == NULL) ? NULL : (var = (_vala_JsonNode_free (var), NULL)))
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _ServicesTodoistProjectsMoveProjectSectionData ServicesTodoistProjectsMoveProjectSectionData;
typedef struct _ServicesTodoistProjectsDuplicateProjectData ServicesTodoistProjectsDuplicateProjectData;

struct _ServicesTodoistProjectsPrivate {
	SoupSession* session;
};

struct _ServicesTodoistProjectsMoveProjectSectionData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ServicesTodoistProjects* self;
	ObjectsBaseObject* base_object;
	gchar* project_id;
	HttpResponse* result;
	HttpResponse* response;
	HttpResponse* _tmp0_;
	ObjectsSource* _tmp1_;
	ObjectsSource* _tmp2_;
	HttpResponse* _tmp3_;
	HttpResponse* _tmp4_;
	HttpResponse* _tmp5_;
	gchar* uuid;
	Util* _tmp6_;
	Util* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* json;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	SoupMessage* message;
	SoupMessage* _tmp12_;
	SoupMessage* _tmp13_;
	SoupMessageHeaders* _tmp14_;
	SoupMessageHeaders* _tmp15_;
	ObjectsSource* _tmp16_;
	ObjectsSource* _tmp17_;
	ObjectsSourceTodoistData* _tmp18_;
	ObjectsSourceTodoistData* _tmp19_;
	const gchar* _tmp20_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	SoupMessage* _tmp24_;
	const gchar* _tmp25_;
	guint8* _tmp26_;
	gint _tmp26__length1;
	gint _tmp27_;
	guint8* _tmp28_;
	gint _tmp28__length1;
	GBytes* _tmp29_;
	GBytes* _tmp30_;
	GBytes* stream;
	SoupSession* _tmp31_;
	SoupMessage* _tmp32_;
	GBytes* _tmp33_;
	JsonParser* parser;
	JsonParser* _tmp34_;
	JsonParser* _tmp35_;
	GBytes* _tmp36_;
	gsize _tmp37_;
	guint8* _tmp38_;
	ServicesTodoist* _tmp39_;
	ServicesTodoist* _tmp40_;
	SoupMessage* _tmp41_;
	guint _tmp42_;
	guint _tmp43_;
	gboolean _tmp44_;
	HttpResponse* _tmp45_;
	JsonParser* _tmp46_;
	JsonNode* _tmp47_;
	SoupMessage* _tmp48_;
	guint _tmp49_;
	guint _tmp50_;
	gchar* _tmp51_;
	gchar* _tmp52_;
	ServicesTodoist* _tmp53_;
	ServicesTodoist* _tmp54_;
	SoupMessage* _tmp55_;
	guint _tmp56_;
	guint _tmp57_;
	gchar* _tmp58_;
	gchar* _tmp59_;
	gchar* _tmp60_;
	gchar* _tmp61_;
	JsonObject* sync_status;
	JsonParser* _tmp62_;
	JsonNode* _tmp63_;
	JsonObject* _tmp64_;
	JsonObject* _tmp65_;
	JsonObject* _tmp66_;
	JsonNode* uuid_member;
	JsonObject* _tmp67_;
	const gchar* _tmp68_;
	JsonNode* _tmp69_;
	JsonNode* _tmp70_;
	JsonNode* _tmp71_;
	ObjectsSource* _tmp72_;
	ObjectsSource* _tmp73_;
	ObjectsSourceTodoistData* _tmp74_;
	ObjectsSourceTodoistData* _tmp75_;
	JsonParser* _tmp76_;
	JsonNode* _tmp77_;
	JsonObject* _tmp78_;
	const gchar* _tmp79_;
	HttpResponse* _tmp80_;
	ObjectsSource* _tmp81_;
	ObjectsSource* _tmp82_;
	GDateTime* _tmp83_;
	GDateTime* _tmp84_;
	gchar* _tmp85_;
	gchar* _tmp86_;
	ObjectsSource* _tmp87_;
	ObjectsSource* _tmp88_;
	HttpResponse* _tmp89_;
	JsonObject* _tmp90_;
	const gchar* _tmp91_;
	JsonObject* _tmp92_;
	const gchar* _tmp93_;
	GError* e;
	ServicesTodoist* _tmp94_;
	ServicesTodoist* _tmp95_;
	SoupMessage* _tmp96_;
	guint _tmp97_;
	guint _tmp98_;
	gboolean _tmp99_;
	HttpResponse* _tmp100_;
	GError* _tmp101_;
	const gchar* _tmp102_;
	ObjectsQueue* queue;
	ObjectsQueue* _tmp103_;
	ObjectsQueue* _tmp104_;
	const gchar* _tmp105_;
	ObjectsQueue* _tmp106_;
	const gchar* _tmp107_;
	const gchar* _tmp108_;
	ObjectsQueue* _tmp109_;
	ObjectsQueue* _tmp110_;
	ObjectsQueue* _tmp111_;
	gchar* _tmp112_;
	gchar* _tmp113_;
	ObjectsQueue* _tmp114_;
	ObjectsSource* _tmp115_;
	ObjectsSource* _tmp116_;
	const gchar* _tmp117_;
	const gchar* _tmp118_;
	HttpResponse* _tmp119_;
	ServicesDatabase* _tmp120_;
	ServicesDatabase* _tmp121_;
	ObjectsQueue* _tmp122_;
	GError* _inner_error0_;
};

struct _ServicesTodoistProjectsDuplicateProjectData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ServicesTodoistProjects* self;
	ObjectsProject* project;
	HttpResponse* result;
	HttpResponse* response;
	HttpResponse* _tmp0_;
	ObjectsSource* _tmp1_;
	ObjectsSource* _tmp2_;
	HttpResponse* _tmp3_;
	HttpResponse* _tmp4_;
	HttpResponse* _tmp5_;
	gchar* json;
	gchar* _tmp6_;
	SoupMessage* message;
	SoupMessage* _tmp7_;
	SoupMessage* _tmp8_;
	SoupMessageHeaders* _tmp9_;
	SoupMessageHeaders* _tmp10_;
	ObjectsSource* _tmp11_;
	ObjectsSource* _tmp12_;
	ObjectsSourceTodoistData* _tmp13_;
	ObjectsSourceTodoistData* _tmp14_;
	const gchar* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	SoupMessage* _tmp19_;
	const gchar* _tmp20_;
	guint8* _tmp21_;
	gint _tmp21__length1;
	gint _tmp22_;
	guint8* _tmp23_;
	gint _tmp23__length1;
	GBytes* _tmp24_;
	GBytes* _tmp25_;
	GBytes* stream;
	SoupSession* _tmp26_;
	SoupMessage* _tmp27_;
	GBytes* _tmp28_;
	JsonParser* parser;
	JsonParser* _tmp29_;
	JsonParser* _tmp30_;
	GBytes* _tmp31_;
	gsize _tmp32_;
	guint8* _tmp33_;
	ServicesTodoist* _tmp34_;
	ServicesTodoist* _tmp35_;
	SoupMessage* _tmp36_;
	guint _tmp37_;
	guint _tmp38_;
	gboolean _tmp39_;
	HttpResponse* _tmp40_;
	JsonParser* _tmp41_;
	JsonNode* _tmp42_;
	SoupMessage* _tmp43_;
	guint _tmp44_;
	guint _tmp45_;
	gchar* _tmp46_;
	gchar* _tmp47_;
	ServicesTodoist* _tmp48_;
	ServicesTodoist* _tmp49_;
	SoupMessage* _tmp50_;
	guint _tmp51_;
	guint _tmp52_;
	gchar* _tmp53_;
	gchar* _tmp54_;
	gchar* _tmp55_;
	gchar* _tmp56_;
	HttpResponse* _tmp57_;
	GError* e;
	ServicesLogService* _tmp58_;
	ServicesLogService* _tmp59_;
	GError* _tmp60_;
	const gchar* _tmp61_;
	gchar* _tmp62_;
	gchar* _tmp63_;
	HttpResponse* _tmp64_;
	GError* _tmp65_;
	const gchar* _tmp66_;
	HttpResponse* _tmp67_;
	GError* _tmp68_;
	GError* _inner_error0_;
};

static gint ServicesTodoistProjects_private_offset;
static gpointer services_todoist_projects_parent_class = NULL;

static void services_todoist_projects_move_project_section_data_free (gpointer _data);
static gboolean services_todoist_projects_move_project_section_co (ServicesTodoistProjectsMoveProjectSectionData* _data_);
static void services_todoist_projects_move_project_section_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
static JsonNode* _vala_JsonNode_copy (JsonNode* self);
static void _vala_JsonNode_free (JsonNode* self);
static void services_todoist_projects_duplicate_project_data_free (gpointer _data);
static gboolean services_todoist_projects_duplicate_project_co (ServicesTodoistProjectsDuplicateProjectData* _data_);
static gchar* services_todoist_projects_get_duplicate_project_json (ServicesTodoistProjects* self,
                                                             ObjectsProject* project);
static void services_todoist_projects_duplicate_project_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_);
static void services_todoist_projects_finalize (GObject * obj);
static GType services_todoist_projects_get_type_once (void);

static inline gpointer
services_todoist_projects_get_instance_private (ServicesTodoistProjects* self)
{
	return G_STRUCT_MEMBER_P (self, ServicesTodoistProjects_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

ServicesTodoistProjects*
services_todoist_projects_construct (GType object_type,
                                     SoupSession* session)
{
	ServicesTodoistProjects * self = NULL;
	SoupSession* _tmp0_;
	g_return_val_if_fail (session != NULL, NULL);
	self = (ServicesTodoistProjects*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (session);
	_g_object_unref0 (self->priv->session);
	self->priv->session = _tmp0_;
	return self;
}

ServicesTodoistProjects*
services_todoist_projects_new (SoupSession* session)
{
	return services_todoist_projects_construct (SERVICES_TYPE_TODOIST_PROJECTS, session);
}

static void
services_todoist_projects_move_project_section_data_free (gpointer _data)
{
	ServicesTodoistProjectsMoveProjectSectionData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->base_object);
	_g_free0 (_data_->project_id);
	_http_response_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (ServicesTodoistProjectsMoveProjectSectionData, _data_);
}

void
services_todoist_projects_move_project_section (ServicesTodoistProjects* self,
                                                ObjectsBaseObject* base_object,
                                                const gchar* project_id,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_)
{
	ServicesTodoistProjectsMoveProjectSectionData* _data_;
	ServicesTodoistProjects* _tmp0_;
	ObjectsBaseObject* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (base_object != NULL);
	g_return_if_fail (project_id != NULL);
	_data_ = g_slice_new0 (ServicesTodoistProjectsMoveProjectSectionData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, services_todoist_projects_move_project_section_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (base_object);
	_g_object_unref0 (_data_->base_object);
	_data_->base_object = _tmp1_;
	_tmp2_ = g_strdup (project_id);
	_g_free0 (_data_->project_id);
	_data_->project_id = _tmp2_;
	services_todoist_projects_move_project_section_co (_data_);
}

HttpResponse*
services_todoist_projects_move_project_section_finish (ServicesTodoistProjects* self,
                                                       GAsyncResult* _res_)
{
	HttpResponse* result;
	ServicesTodoistProjectsMoveProjectSectionData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static void
services_todoist_projects_move_project_section_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	ServicesTodoistProjectsMoveProjectSectionData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	services_todoist_projects_move_project_section_co (_data_);
}

static gpointer
_json_object_ref0 (gpointer self)
{
	return self ? json_object_ref (self) : NULL;
}

static JsonNode*
_vala_JsonNode_copy (JsonNode* self)
{
	return g_boxed_copy (json_node_get_type (), self);
}

static gpointer
__vala_JsonNode_copy0 (gpointer self)
{
	return self ? _vala_JsonNode_copy (self) : NULL;
}

static gchar*
g_date_time_to_string (GDateTime* self)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_date_time_format (self, "%FT%H:%M:%S%z");
	result = _tmp0_;
	return result;
}

static void
_vala_JsonNode_free (JsonNode* self)
{
	g_boxed_free (json_node_get_type (), self);
}

static gboolean
services_todoist_projects_move_project_section_co (ServicesTodoistProjectsMoveProjectSectionData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = http_response_new ();
	_data_->response = _data_->_tmp0_;
	_data_->_tmp1_ = objects_base_object_get_source (_data_->base_object);
	_data_->_tmp2_ = _data_->_tmp1_;
	if (objects_source_needs_migration (_data_->_tmp2_)) {
		_data_->_tmp3_ = _data_->response;
		http_response_set_status (_data_->_tmp3_, FALSE);
		_data_->_tmp4_ = _data_->response;
		http_response_set_error (_data_->_tmp4_, SERVICES_TODOIST_PROJECTS_MIGRATE_MESSAGE);
		_data_->_tmp5_ = _data_->response;
		http_response_set_error_code (_data_->_tmp5_, 410);
		_data_->result = _data_->response;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp6_ = util_get_default ();
	_data_->_tmp7_ = _data_->_tmp6_;
	_data_->_tmp8_ = util_generate_string (_data_->_tmp7_);
	_data_->_tmp9_ = _data_->_tmp8_;
	_g_object_unref0 (_data_->_tmp7_);
	_data_->uuid = _data_->_tmp9_;
	_data_->_tmp10_ = _data_->uuid;
	_data_->_tmp11_ = objects_base_object_get_move_json (_data_->base_object, _data_->_tmp10_, _data_->project_id);
	_data_->json = _data_->_tmp11_;
	_data_->_tmp12_ = soup_message_new ("POST", SERVICES_TODOIST_PROJECTS_TODOIST_SYNC_URL);
	_data_->message = _data_->_tmp12_;
	_data_->_tmp13_ = _data_->message;
	_data_->_tmp14_ = soup_message_get_request_headers (_data_->_tmp13_);
	_data_->_tmp15_ = _data_->_tmp14_;
	_data_->_tmp16_ = objects_base_object_get_source (_data_->base_object);
	_data_->_tmp17_ = _data_->_tmp16_;
	_data_->_tmp18_ = objects_source_get_todoist_data (_data_->_tmp17_);
	_data_->_tmp19_ = _data_->_tmp18_;
	_data_->_tmp20_ = objects_source_todoist_data_get_access_token (_data_->_tmp19_);
	_data_->_tmp21_ = _data_->_tmp20_;
	_data_->_tmp22_ = g_strdup_printf ("Bearer %s", _data_->_tmp21_);
	_data_->_tmp23_ = _data_->_tmp22_;
	soup_message_headers_append (_data_->_tmp15_, "Authorization", _data_->_tmp23_);
	_g_free0 (_data_->_tmp23_);
	_data_->_tmp24_ = _data_->message;
	_data_->_tmp25_ = _data_->json;
	_data_->_tmp27_ = 0;
	_data_->_tmp26_ = string_get_data (_data_->_tmp25_, &_data_->_tmp27_);
	_data_->_tmp26__length1 = _data_->_tmp27_;
	_data_->_tmp28_ = _data_->_tmp26_;
	_data_->_tmp28__length1 = _data_->_tmp26__length1;
	_data_->_tmp29_ = g_bytes_new (_data_->_tmp28_, _data_->_tmp28__length1);
	_data_->_tmp30_ = _data_->_tmp29_;
	soup_message_set_request_body_from_bytes (_data_->_tmp24_, "application/json", _data_->_tmp30_);
	_g_bytes_unref0 (_data_->_tmp30_);
	{
		_data_->_tmp31_ = _data_->self->priv->session;
		_data_->_tmp32_ = _data_->message;
		_data_->_state_ = 1;
		soup_session_send_and_read_async (_data_->_tmp31_, _data_->_tmp32_, G_PRIORITY_HIGH, NULL, services_todoist_projects_move_project_section_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp33_ = soup_session_send_and_read_finish (_data_->_tmp31_, _data_->_res_, &_data_->_inner_error0_);
		_data_->stream = _data_->_tmp33_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp34_ = json_parser_new ();
		_data_->parser = _data_->_tmp34_;
		_data_->_tmp35_ = _data_->parser;
		_data_->_tmp36_ = _data_->stream;
		_data_->_tmp37_ = 0;
		_data_->_tmp38_ = g_bytes_get_data (_data_->_tmp36_, &_data_->_tmp37_);
		json_parser_load_from_data (_data_->_tmp35_, (const gchar*) _data_->_tmp38_, (gssize) -1, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->parser);
			_g_bytes_unref0 (_data_->stream);
			goto __catch0_g_error;
		}
		_data_->_tmp39_ = services_todoist_get_default ();
		_data_->_tmp40_ = _data_->_tmp39_;
		_data_->_tmp41_ = _data_->message;
		g_object_get (_data_->_tmp41_, "status-code", &_data_->_tmp42_, NULL);
		_data_->_tmp43_ = _data_->_tmp42_;
		_data_->_tmp44_ = services_todoist_is_todoist_error (_data_->_tmp40_, _data_->_tmp43_);
		_g_object_unref0 (_data_->_tmp40_);
		if (_data_->_tmp44_) {
			_data_->_tmp45_ = _data_->response;
			_data_->_tmp46_ = _data_->parser;
			_data_->_tmp47_ = json_parser_get_root (_data_->_tmp46_);
			http_response_from_error_json (_data_->_tmp45_, _data_->_tmp47_);
			_data_->_tmp48_ = _data_->message;
			g_object_get (_data_->_tmp48_, "status-code", &_data_->_tmp49_, NULL);
			_data_->_tmp50_ = _data_->_tmp49_;
			_data_->_tmp51_ = g_strdup_printf ("%u", _data_->_tmp50_);
			_data_->_tmp52_ = _data_->_tmp51_;
			_data_->_tmp53_ = services_todoist_get_default ();
			_data_->_tmp54_ = _data_->_tmp53_;
			_data_->_tmp55_ = _data_->message;
			g_object_get (_data_->_tmp55_, "status-code", &_data_->_tmp56_, NULL);
			_data_->_tmp57_ = _data_->_tmp56_;
			_data_->_tmp58_ = services_todoist_get_todoist_error (_data_->_tmp54_, _data_->_tmp57_);
			_data_->_tmp59_ = _data_->_tmp58_;
			_data_->_tmp60_ = g_strdup_printf ("Code: %s - %s", _data_->_tmp52_, _data_->_tmp59_);
			_data_->_tmp61_ = _data_->_tmp60_;
			g_debug ("TodoistProjects.vala:56: %s", _data_->_tmp61_);
			_g_free0 (_data_->_tmp61_);
			_g_free0 (_data_->_tmp59_);
			_g_object_unref0 (_data_->_tmp54_);
			_g_free0 (_data_->_tmp52_);
		} else {
			_data_->_tmp62_ = _data_->parser;
			_data_->_tmp63_ = json_parser_get_root (_data_->_tmp62_);
			_data_->_tmp64_ = json_node_get_object (_data_->_tmp63_);
			_data_->_tmp65_ = json_object_get_object_member (_data_->_tmp64_, "sync_status");
			_data_->_tmp66_ = _json_object_ref0 (_data_->_tmp65_);
			_data_->sync_status = _data_->_tmp66_;
			_data_->_tmp67_ = _data_->sync_status;
			_data_->_tmp68_ = _data_->uuid;
			_data_->_tmp69_ = json_object_get_member (_data_->_tmp67_, _data_->_tmp68_);
			_data_->_tmp70_ = __vala_JsonNode_copy0 (_data_->_tmp69_);
			_data_->uuid_member = _data_->_tmp70_;
			_data_->_tmp71_ = _data_->uuid_member;
			if (json_node_get_node_type (_data_->_tmp71_) == JSON_NODE_VALUE) {
				_data_->_tmp72_ = objects_base_object_get_source (_data_->base_object);
				_data_->_tmp73_ = _data_->_tmp72_;
				_data_->_tmp74_ = objects_source_get_todoist_data (_data_->_tmp73_);
				_data_->_tmp75_ = _data_->_tmp74_;
				_data_->_tmp76_ = _data_->parser;
				_data_->_tmp77_ = json_parser_get_root (_data_->_tmp76_);
				_data_->_tmp78_ = json_node_get_object (_data_->_tmp77_);
				_data_->_tmp79_ = json_object_get_string_member (_data_->_tmp78_, "sync_token");
				objects_source_todoist_data_set_sync_token (_data_->_tmp75_, _data_->_tmp79_);
				_data_->_tmp80_ = _data_->response;
				http_response_set_status (_data_->_tmp80_, TRUE);
				_data_->_tmp81_ = objects_base_object_get_source (_data_->base_object);
				_data_->_tmp82_ = _data_->_tmp81_;
				_data_->_tmp83_ = g_date_time_new_now_local ();
				_data_->_tmp84_ = _data_->_tmp83_;
				_data_->_tmp85_ = g_date_time_to_string (_data_->_tmp84_);
				_data_->_tmp86_ = _data_->_tmp85_;
				objects_source_set_last_sync (_data_->_tmp82_, _data_->_tmp86_);
				_g_free0 (_data_->_tmp86_);
				_g_date_time_unref0 (_data_->_tmp84_);
				_data_->_tmp87_ = objects_base_object_get_source (_data_->base_object);
				_data_->_tmp88_ = _data_->_tmp87_;
				objects_source_save (_data_->_tmp88_);
			} else {
				_data_->_tmp89_ = _data_->response;
				_data_->_tmp90_ = _data_->sync_status;
				_data_->_tmp91_ = _data_->uuid;
				_data_->_tmp92_ = json_object_get_object_member (_data_->_tmp90_, _data_->_tmp91_);
				_data_->_tmp93_ = json_object_get_string_member (_data_->_tmp92_, "error");
				http_response_set_error (_data_->_tmp89_, _data_->_tmp93_);
			}
			__vala_JsonNode_free0 (_data_->uuid_member);
			_json_object_unref0 (_data_->sync_status);
		}
		_g_object_unref0 (_data_->parser);
		_g_bytes_unref0 (_data_->stream);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp94_ = services_todoist_get_default ();
		_data_->_tmp95_ = _data_->_tmp94_;
		_data_->_tmp96_ = _data_->message;
		g_object_get (_data_->_tmp96_, "status-code", &_data_->_tmp97_, NULL);
		_data_->_tmp98_ = _data_->_tmp97_;
		_data_->_tmp99_ = services_todoist_is_todoist_error (_data_->_tmp95_, _data_->_tmp98_);
		_g_object_unref0 (_data_->_tmp95_);
		if (_data_->_tmp99_) {
			_data_->_tmp100_ = _data_->response;
			_data_->_tmp101_ = _data_->e;
			_data_->_tmp102_ = _data_->_tmp101_->message;
			http_response_set_error (_data_->_tmp100_, _data_->_tmp102_);
		} else {
			_data_->_tmp103_ = objects_queue_new ();
			_data_->queue = _data_->_tmp103_;
			_data_->_tmp104_ = _data_->queue;
			_data_->_tmp105_ = _data_->uuid;
			objects_queue_set_uuid (_data_->_tmp104_, _data_->_tmp105_);
			_data_->_tmp106_ = _data_->queue;
			_data_->_tmp107_ = objects_base_object_get_id (_data_->base_object);
			_data_->_tmp108_ = _data_->_tmp107_;
			objects_queue_set_object_id (_data_->_tmp106_, _data_->_tmp108_);
			if (OBJECTS_IS_PROJECT (_data_->base_object)) {
				_data_->_tmp109_ = _data_->queue;
				objects_queue_set_query (_data_->_tmp109_, "project_move");
			} else {
				_data_->_tmp110_ = _data_->queue;
				objects_queue_set_query (_data_->_tmp110_, "section_move");
			}
			_data_->_tmp111_ = _data_->queue;
			_data_->_tmp112_ = objects_base_object_to_json (_data_->base_object);
			_data_->_tmp113_ = _data_->_tmp112_;
			objects_queue_set_args (_data_->_tmp111_, _data_->_tmp113_);
			_g_free0 (_data_->_tmp113_);
			_data_->_tmp114_ = _data_->queue;
			_data_->_tmp115_ = objects_base_object_get_source (_data_->base_object);
			_data_->_tmp116_ = _data_->_tmp115_;
			_data_->_tmp117_ = objects_base_object_get_id ((ObjectsBaseObject*) _data_->_tmp116_);
			_data_->_tmp118_ = _data_->_tmp117_;
			objects_queue_set_source_id (_data_->_tmp114_, _data_->_tmp118_);
			_data_->_tmp119_ = _data_->response;
			http_response_set_status (_data_->_tmp119_, TRUE);
			_data_->_tmp120_ = services_database_get_default ();
			_data_->_tmp121_ = _data_->_tmp120_;
			_data_->_tmp122_ = _data_->queue;
			services_database_insert_queue (_data_->_tmp121_, _data_->_tmp122_);
			_g_object_unref0 (_data_->_tmp121_);
			_g_object_unref0 (_data_->queue);
		}
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->message);
		_g_free0 (_data_->json);
		_g_free0 (_data_->uuid);
		_http_response_unref0 (_data_->response);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->response;
	_g_object_unref0 (_data_->message);
	_g_free0 (_data_->json);
	_g_free0 (_data_->uuid);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
services_todoist_projects_duplicate_project_data_free (gpointer _data)
{
	ServicesTodoistProjectsDuplicateProjectData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->project);
	_http_response_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (ServicesTodoistProjectsDuplicateProjectData, _data_);
}

void
services_todoist_projects_duplicate_project (ServicesTodoistProjects* self,
                                             ObjectsProject* project,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	ServicesTodoistProjectsDuplicateProjectData* _data_;
	ServicesTodoistProjects* _tmp0_;
	ObjectsProject* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (project != NULL);
	_data_ = g_slice_new0 (ServicesTodoistProjectsDuplicateProjectData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, services_todoist_projects_duplicate_project_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (project);
	_g_object_unref0 (_data_->project);
	_data_->project = _tmp1_;
	services_todoist_projects_duplicate_project_co (_data_);
}

HttpResponse*
services_todoist_projects_duplicate_project_finish (ServicesTodoistProjects* self,
                                                    GAsyncResult* _res_)
{
	HttpResponse* result;
	ServicesTodoistProjectsDuplicateProjectData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
services_todoist_projects_duplicate_project_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_)
{
	ServicesTodoistProjectsDuplicateProjectData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	services_todoist_projects_duplicate_project_co (_data_);
}

static gboolean
services_todoist_projects_duplicate_project_co (ServicesTodoistProjectsDuplicateProjectData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = http_response_new ();
	_data_->response = _data_->_tmp0_;
	_data_->_tmp1_ = objects_project_get_source (_data_->project);
	_data_->_tmp2_ = _data_->_tmp1_;
	if (objects_source_needs_migration (_data_->_tmp2_)) {
		_data_->_tmp3_ = _data_->response;
		http_response_set_status (_data_->_tmp3_, FALSE);
		_data_->_tmp4_ = _data_->response;
		http_response_set_error (_data_->_tmp4_, SERVICES_TODOIST_PROJECTS_MIGRATE_MESSAGE);
		_data_->_tmp5_ = _data_->response;
		http_response_set_error_code (_data_->_tmp5_, 410);
		_data_->result = _data_->response;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp6_ = services_todoist_projects_get_duplicate_project_json (_data_->self, _data_->project);
	_data_->json = _data_->_tmp6_;
	_data_->_tmp7_ = soup_message_new ("POST", SERVICES_TODOIST_PROJECTS_TODOIST_SYNC_URL);
	_data_->message = _data_->_tmp7_;
	_data_->_tmp8_ = _data_->message;
	_data_->_tmp9_ = soup_message_get_request_headers (_data_->_tmp8_);
	_data_->_tmp10_ = _data_->_tmp9_;
	_data_->_tmp11_ = objects_project_get_source (_data_->project);
	_data_->_tmp12_ = _data_->_tmp11_;
	_data_->_tmp13_ = objects_source_get_todoist_data (_data_->_tmp12_);
	_data_->_tmp14_ = _data_->_tmp13_;
	_data_->_tmp15_ = objects_source_todoist_data_get_access_token (_data_->_tmp14_);
	_data_->_tmp16_ = _data_->_tmp15_;
	_data_->_tmp17_ = g_strdup_printf ("Bearer %s", _data_->_tmp16_);
	_data_->_tmp18_ = _data_->_tmp17_;
	soup_message_headers_append (_data_->_tmp10_, "Authorization", _data_->_tmp18_);
	_g_free0 (_data_->_tmp18_);
	_data_->_tmp19_ = _data_->message;
	_data_->_tmp20_ = _data_->json;
	_data_->_tmp22_ = 0;
	_data_->_tmp21_ = string_get_data (_data_->_tmp20_, &_data_->_tmp22_);
	_data_->_tmp21__length1 = _data_->_tmp22_;
	_data_->_tmp23_ = _data_->_tmp21_;
	_data_->_tmp23__length1 = _data_->_tmp21__length1;
	_data_->_tmp24_ = g_bytes_new (_data_->_tmp23_, _data_->_tmp23__length1);
	_data_->_tmp25_ = _data_->_tmp24_;
	soup_message_set_request_body_from_bytes (_data_->_tmp19_, "application/json", _data_->_tmp25_);
	_g_bytes_unref0 (_data_->_tmp25_);
	{
		_data_->_tmp26_ = _data_->self->priv->session;
		_data_->_tmp27_ = _data_->message;
		_data_->_state_ = 1;
		soup_session_send_and_read_async (_data_->_tmp26_, _data_->_tmp27_, G_PRIORITY_HIGH, NULL, services_todoist_projects_duplicate_project_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp28_ = soup_session_send_and_read_finish (_data_->_tmp26_, _data_->_res_, &_data_->_inner_error0_);
		_data_->stream = _data_->_tmp28_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp29_ = json_parser_new ();
		_data_->parser = _data_->_tmp29_;
		_data_->_tmp30_ = _data_->parser;
		_data_->_tmp31_ = _data_->stream;
		_data_->_tmp32_ = 0;
		_data_->_tmp33_ = g_bytes_get_data (_data_->_tmp31_, &_data_->_tmp32_);
		json_parser_load_from_data (_data_->_tmp30_, (const gchar*) _data_->_tmp33_, (gssize) -1, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->parser);
			_g_bytes_unref0 (_data_->stream);
			goto __catch0_g_error;
		}
		_data_->_tmp34_ = services_todoist_get_default ();
		_data_->_tmp35_ = _data_->_tmp34_;
		_data_->_tmp36_ = _data_->message;
		g_object_get (_data_->_tmp36_, "status-code", &_data_->_tmp37_, NULL);
		_data_->_tmp38_ = _data_->_tmp37_;
		_data_->_tmp39_ = services_todoist_is_todoist_error (_data_->_tmp35_, _data_->_tmp38_);
		_g_object_unref0 (_data_->_tmp35_);
		if (_data_->_tmp39_) {
			_data_->_tmp40_ = _data_->response;
			_data_->_tmp41_ = _data_->parser;
			_data_->_tmp42_ = json_parser_get_root (_data_->_tmp41_);
			http_response_from_error_json (_data_->_tmp40_, _data_->_tmp42_);
			_data_->_tmp43_ = _data_->message;
			g_object_get (_data_->_tmp43_, "status-code", &_data_->_tmp44_, NULL);
			_data_->_tmp45_ = _data_->_tmp44_;
			_data_->_tmp46_ = g_strdup_printf ("%u", _data_->_tmp45_);
			_data_->_tmp47_ = _data_->_tmp46_;
			_data_->_tmp48_ = services_todoist_get_default ();
			_data_->_tmp49_ = _data_->_tmp48_;
			_data_->_tmp50_ = _data_->message;
			g_object_get (_data_->_tmp50_, "status-code", &_data_->_tmp51_, NULL);
			_data_->_tmp52_ = _data_->_tmp51_;
			_data_->_tmp53_ = services_todoist_get_todoist_error (_data_->_tmp49_, _data_->_tmp52_);
			_data_->_tmp54_ = _data_->_tmp53_;
			_data_->_tmp55_ = g_strdup_printf ("Code: %s - %s", _data_->_tmp47_, _data_->_tmp54_);
			_data_->_tmp56_ = _data_->_tmp55_;
			g_debug ("TodoistProjects.vala:115: %s", _data_->_tmp56_);
			_g_free0 (_data_->_tmp56_);
			_g_free0 (_data_->_tmp54_);
			_g_object_unref0 (_data_->_tmp49_);
			_g_free0 (_data_->_tmp47_);
		} else {
			_data_->_tmp57_ = _data_->response;
			http_response_set_status (_data_->_tmp57_, TRUE);
		}
		_g_object_unref0 (_data_->parser);
		_g_bytes_unref0 (_data_->stream);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp58_ = services_log_service_get_default ();
		_data_->_tmp59_ = _data_->_tmp58_;
		_data_->_tmp60_ = _data_->e;
		_data_->_tmp61_ = _data_->_tmp60_->message;
		_data_->_tmp62_ = g_strdup_printf ("Failed to duplicate project: %s", _data_->_tmp61_);
		_data_->_tmp63_ = _data_->_tmp62_;
		services_log_service_error (_data_->_tmp59_, "Todoist", _data_->_tmp63_);
		_g_free0 (_data_->_tmp63_);
		_g_object_unref0 (_data_->_tmp59_);
		_data_->_tmp64_ = _data_->response;
		_data_->_tmp65_ = _data_->e;
		_data_->_tmp66_ = _data_->_tmp65_->message;
		http_response_set_error (_data_->_tmp64_, _data_->_tmp66_);
		_data_->_tmp67_ = _data_->response;
		_data_->_tmp68_ = _data_->e;
		http_response_set_error_code (_data_->_tmp67_, _data_->_tmp68_->code);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->message);
		_g_free0 (_data_->json);
		_http_response_unref0 (_data_->response);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->response;
	_g_object_unref0 (_data_->message);
	_g_free0 (_data_->json);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gchar*
services_todoist_projects_get_duplicate_project_json (ServicesTodoistProjects* self,
                                                      ObjectsProject* project)
{
	JsonBuilder* builder = NULL;
	JsonBuilder* _tmp0_;
	JsonBuilder* _tmp1_;
	JsonBuilder* _tmp2_;
	JsonBuilder* _tmp3_;
	JsonBuilder* _tmp4_;
	JsonBuilder* _tmp5_;
	JsonBuilder* _tmp6_;
	JsonBuilder* _tmp7_;
	JsonBuilder* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	JsonBuilder* _tmp13_;
	JsonBuilder* _tmp14_;
	Util* _tmp15_;
	Util* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	JsonBuilder* _tmp19_;
	JsonBuilder* _tmp20_;
	JsonBuilder* _tmp21_;
	JsonBuilder* _tmp22_;
	const gchar* _tmp23_;
	const gchar* _tmp24_;
	JsonBuilder* _tmp25_;
	JsonBuilder* _tmp26_;
	const gchar* _tmp27_;
	const gchar* _tmp28_;
	JsonBuilder* _tmp29_;
	JsonBuilder* _tmp30_;
	JsonBuilder* _tmp177_;
	JsonBuilder* _tmp178_;
	JsonGenerator* generator = NULL;
	JsonGenerator* _tmp179_;
	JsonBuilder* _tmp180_;
	JsonNode* _tmp181_;
	JsonNode* _tmp182_;
	gchar* _tmp183_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (project != NULL, NULL);
	_tmp0_ = json_builder_new ();
	builder = _tmp0_;
	_tmp1_ = builder;
	json_builder_begin_object (_tmp1_);
	_tmp2_ = builder;
	json_builder_set_member_name (_tmp2_, "commands");
	_tmp3_ = builder;
	json_builder_begin_array (_tmp3_);
	_tmp4_ = builder;
	json_builder_begin_object (_tmp4_);
	_tmp5_ = builder;
	json_builder_set_member_name (_tmp5_, "type");
	_tmp6_ = builder;
	json_builder_add_string_value (_tmp6_, "project_add");
	_tmp7_ = builder;
	json_builder_set_member_name (_tmp7_, "temp_id");
	_tmp8_ = builder;
	_tmp9_ = objects_base_object_get_id ((ObjectsBaseObject*) project);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_strconcat ("_", _tmp10_, NULL);
	_tmp12_ = _tmp11_;
	json_builder_add_string_value (_tmp8_, _tmp12_);
	_g_free0 (_tmp12_);
	_tmp13_ = builder;
	json_builder_set_member_name (_tmp13_, "uuid");
	_tmp14_ = builder;
	_tmp15_ = util_get_default ();
	_tmp16_ = _tmp15_;
	_tmp17_ = util_generate_string (_tmp16_);
	_tmp18_ = _tmp17_;
	json_builder_add_string_value (_tmp14_, _tmp18_);
	_g_free0 (_tmp18_);
	_g_object_unref0 (_tmp16_);
	_tmp19_ = builder;
	json_builder_set_member_name (_tmp19_, "args");
	_tmp20_ = builder;
	json_builder_begin_object (_tmp20_);
	_tmp21_ = builder;
	json_builder_set_member_name (_tmp21_, "name");
	_tmp22_ = builder;
	_tmp23_ = objects_base_object_get_name ((ObjectsBaseObject*) project);
	_tmp24_ = _tmp23_;
	json_builder_add_string_value (_tmp22_, _tmp24_);
	_tmp25_ = builder;
	json_builder_set_member_name (_tmp25_, "color");
	_tmp26_ = builder;
	_tmp27_ = objects_base_object_get_color ((ObjectsBaseObject*) project);
	_tmp28_ = _tmp27_;
	json_builder_add_string_value (_tmp26_, _tmp28_);
	_tmp29_ = builder;
	json_builder_end_object (_tmp29_);
	_tmp30_ = builder;
	json_builder_end_object (_tmp30_);
	{
		GeeArrayList* _section_list = NULL;
		GeeArrayList* _tmp31_;
		GeeArrayList* _tmp32_;
		gint _section_size = 0;
		GeeArrayList* _tmp33_;
		gint _tmp34_;
		gint _tmp35_;
		gint _section_index = 0;
		_tmp31_ = objects_project_get_sections (project);
		_tmp32_ = _tmp31_;
		_section_list = _tmp32_;
		_tmp33_ = _section_list;
		_tmp34_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp33_);
		_tmp35_ = _tmp34_;
		_section_size = _tmp35_;
		_section_index = -1;
		while (TRUE) {
			gint _tmp36_;
			gint _tmp37_;
			ObjectsSection* section = NULL;
			GeeArrayList* _tmp38_;
			gpointer _tmp39_;
			JsonBuilder* _tmp40_;
			JsonBuilder* _tmp41_;
			JsonBuilder* _tmp42_;
			JsonBuilder* _tmp43_;
			JsonBuilder* _tmp44_;
			ObjectsSection* _tmp45_;
			const gchar* _tmp46_;
			const gchar* _tmp47_;
			gchar* _tmp48_;
			gchar* _tmp49_;
			JsonBuilder* _tmp50_;
			JsonBuilder* _tmp51_;
			Util* _tmp52_;
			Util* _tmp53_;
			gchar* _tmp54_;
			gchar* _tmp55_;
			JsonBuilder* _tmp56_;
			JsonBuilder* _tmp57_;
			JsonBuilder* _tmp58_;
			JsonBuilder* _tmp59_;
			ObjectsSection* _tmp60_;
			const gchar* _tmp61_;
			const gchar* _tmp62_;
			JsonBuilder* _tmp63_;
			JsonBuilder* _tmp64_;
			ObjectsSection* _tmp65_;
			const gchar* _tmp66_;
			const gchar* _tmp67_;
			gchar* _tmp68_;
			gchar* _tmp69_;
			JsonBuilder* _tmp70_;
			JsonBuilder* _tmp71_;
			_section_index = _section_index + 1;
			_tmp36_ = _section_index;
			_tmp37_ = _section_size;
			if (!(_tmp36_ < _tmp37_)) {
				break;
			}
			_tmp38_ = _section_list;
			_tmp39_ = gee_abstract_list_get ((GeeAbstractList*) _tmp38_, _section_index);
			section = (ObjectsSection*) _tmp39_;
			_tmp40_ = builder;
			json_builder_begin_object (_tmp40_);
			_tmp41_ = builder;
			json_builder_set_member_name (_tmp41_, "type");
			_tmp42_ = builder;
			json_builder_add_string_value (_tmp42_, "section_add");
			_tmp43_ = builder;
			json_builder_set_member_name (_tmp43_, "temp_id");
			_tmp44_ = builder;
			_tmp45_ = section;
			_tmp46_ = objects_base_object_get_id ((ObjectsBaseObject*) _tmp45_);
			_tmp47_ = _tmp46_;
			_tmp48_ = g_strconcat ("_", _tmp47_, NULL);
			_tmp49_ = _tmp48_;
			json_builder_add_string_value (_tmp44_, _tmp49_);
			_g_free0 (_tmp49_);
			_tmp50_ = builder;
			json_builder_set_member_name (_tmp50_, "uuid");
			_tmp51_ = builder;
			_tmp52_ = util_get_default ();
			_tmp53_ = _tmp52_;
			_tmp54_ = util_generate_string (_tmp53_);
			_tmp55_ = _tmp54_;
			json_builder_add_string_value (_tmp51_, _tmp55_);
			_g_free0 (_tmp55_);
			_g_object_unref0 (_tmp53_);
			_tmp56_ = builder;
			json_builder_set_member_name (_tmp56_, "args");
			_tmp57_ = builder;
			json_builder_begin_object (_tmp57_);
			_tmp58_ = builder;
			json_builder_set_member_name (_tmp58_, "name");
			_tmp59_ = builder;
			_tmp60_ = section;
			_tmp61_ = objects_base_object_get_name ((ObjectsBaseObject*) _tmp60_);
			_tmp62_ = _tmp61_;
			json_builder_add_string_value (_tmp59_, _tmp62_);
			_tmp63_ = builder;
			json_builder_set_member_name (_tmp63_, "project_id");
			_tmp64_ = builder;
			_tmp65_ = section;
			_tmp66_ = objects_section_get_project_id (_tmp65_);
			_tmp67_ = _tmp66_;
			_tmp68_ = g_strconcat ("_", _tmp67_, NULL);
			_tmp69_ = _tmp68_;
			json_builder_add_string_value (_tmp64_, _tmp69_);
			_g_free0 (_tmp69_);
			_tmp70_ = builder;
			json_builder_end_object (_tmp70_);
			_tmp71_ = builder;
			json_builder_end_object (_tmp71_);
			_g_object_unref0 (section);
		}
	}
	{
		GeeArrayList* _item_list = NULL;
		GeeArrayList* _tmp72_;
		GeeArrayList* _tmp73_;
		gint _item_size = 0;
		GeeArrayList* _tmp74_;
		gint _tmp75_;
		gint _tmp76_;
		gint _item_index = 0;
		_tmp72_ = objects_project_get_all_items (project);
		_tmp73_ = _tmp72_;
		_item_list = _tmp73_;
		_tmp74_ = _item_list;
		_tmp75_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp74_);
		_tmp76_ = _tmp75_;
		_item_size = _tmp76_;
		_item_index = -1;
		while (TRUE) {
			gint _tmp77_;
			gint _tmp78_;
			ObjectsItem* item = NULL;
			GeeArrayList* _tmp79_;
			gpointer _tmp80_;
			JsonBuilder* _tmp81_;
			JsonBuilder* _tmp82_;
			JsonBuilder* _tmp83_;
			JsonBuilder* _tmp84_;
			JsonBuilder* _tmp85_;
			ObjectsItem* _tmp86_;
			const gchar* _tmp87_;
			const gchar* _tmp88_;
			gchar* _tmp89_;
			gchar* _tmp90_;
			JsonBuilder* _tmp91_;
			JsonBuilder* _tmp92_;
			Util* _tmp93_;
			Util* _tmp94_;
			gchar* _tmp95_;
			gchar* _tmp96_;
			JsonBuilder* _tmp97_;
			JsonBuilder* _tmp98_;
			JsonBuilder* _tmp99_;
			JsonBuilder* _tmp100_;
			ObjectsItem* _tmp101_;
			const gchar* _tmp102_;
			const gchar* _tmp103_;
			JsonBuilder* _tmp104_;
			JsonBuilder* _tmp105_;
			ObjectsItem* _tmp106_;
			const gchar* _tmp107_;
			const gchar* _tmp108_;
			JsonBuilder* _tmp109_;
			JsonBuilder* _tmp110_;
			ObjectsItem* _tmp111_;
			const gchar* _tmp112_;
			const gchar* _tmp113_;
			gchar* _tmp114_;
			gchar* _tmp115_;
			ObjectsItem* _tmp116_;
			const gchar* _tmp117_;
			const gchar* _tmp118_;
			ObjectsItem* _tmp126_;
			const gchar* _tmp127_;
			const gchar* _tmp128_;
			JsonBuilder* _tmp136_;
			gint _tmp137_ = 0;
			ObjectsItem* _tmp138_;
			gint _tmp139_;
			gint _tmp140_;
			JsonBuilder* _tmp144_;
			ObjectsItem* _tmp145_;
			gboolean _tmp146_;
			gboolean _tmp147_;
			JsonBuilder* _tmp158_;
			JsonBuilder* _tmp159_;
			JsonBuilder* _tmp174_;
			JsonBuilder* _tmp175_;
			JsonBuilder* _tmp176_;
			_item_index = _item_index + 1;
			_tmp77_ = _item_index;
			_tmp78_ = _item_size;
			if (!(_tmp77_ < _tmp78_)) {
				break;
			}
			_tmp79_ = _item_list;
			_tmp80_ = gee_abstract_list_get ((GeeAbstractList*) _tmp79_, _item_index);
			item = (ObjectsItem*) _tmp80_;
			_tmp81_ = builder;
			json_builder_begin_object (_tmp81_);
			_tmp82_ = builder;
			json_builder_set_member_name (_tmp82_, "type");
			_tmp83_ = builder;
			json_builder_add_string_value (_tmp83_, "item_add");
			_tmp84_ = builder;
			json_builder_set_member_name (_tmp84_, "temp_id");
			_tmp85_ = builder;
			_tmp86_ = item;
			_tmp87_ = objects_base_object_get_id ((ObjectsBaseObject*) _tmp86_);
			_tmp88_ = _tmp87_;
			_tmp89_ = g_strconcat ("_", _tmp88_, NULL);
			_tmp90_ = _tmp89_;
			json_builder_add_string_value (_tmp85_, _tmp90_);
			_g_free0 (_tmp90_);
			_tmp91_ = builder;
			json_builder_set_member_name (_tmp91_, "uuid");
			_tmp92_ = builder;
			_tmp93_ = util_get_default ();
			_tmp94_ = _tmp93_;
			_tmp95_ = util_generate_string (_tmp94_);
			_tmp96_ = _tmp95_;
			json_builder_add_string_value (_tmp92_, _tmp96_);
			_g_free0 (_tmp96_);
			_g_object_unref0 (_tmp94_);
			_tmp97_ = builder;
			json_builder_set_member_name (_tmp97_, "args");
			_tmp98_ = builder;
			json_builder_begin_object (_tmp98_);
			_tmp99_ = builder;
			json_builder_set_member_name (_tmp99_, "content");
			_tmp100_ = builder;
			_tmp101_ = item;
			_tmp102_ = objects_item_get_content (_tmp101_);
			_tmp103_ = _tmp102_;
			json_builder_add_string_value (_tmp100_, _tmp103_);
			_tmp104_ = builder;
			json_builder_set_member_name (_tmp104_, "description");
			_tmp105_ = builder;
			_tmp106_ = item;
			_tmp107_ = objects_item_get_description (_tmp106_);
			_tmp108_ = _tmp107_;
			json_builder_add_string_value (_tmp105_, _tmp108_);
			_tmp109_ = builder;
			json_builder_set_member_name (_tmp109_, "project_id");
			_tmp110_ = builder;
			_tmp111_ = item;
			_tmp112_ = objects_item_get_project_id (_tmp111_);
			_tmp113_ = _tmp112_;
			_tmp114_ = g_strconcat ("_", _tmp113_, NULL);
			_tmp115_ = _tmp114_;
			json_builder_add_string_value (_tmp110_, _tmp115_);
			_g_free0 (_tmp115_);
			_tmp116_ = item;
			_tmp117_ = objects_item_get_parent_id (_tmp116_);
			_tmp118_ = _tmp117_;
			if (g_strcmp0 (_tmp118_, "") != 0) {
				JsonBuilder* _tmp119_;
				JsonBuilder* _tmp120_;
				ObjectsItem* _tmp121_;
				const gchar* _tmp122_;
				const gchar* _tmp123_;
				gchar* _tmp124_;
				gchar* _tmp125_;
				_tmp119_ = builder;
				json_builder_set_member_name (_tmp119_, "parent_id");
				_tmp120_ = builder;
				_tmp121_ = item;
				_tmp122_ = objects_item_get_parent_id (_tmp121_);
				_tmp123_ = _tmp122_;
				_tmp124_ = g_strconcat ("_", _tmp123_, NULL);
				_tmp125_ = _tmp124_;
				json_builder_add_string_value (_tmp120_, _tmp125_);
				_g_free0 (_tmp125_);
			}
			_tmp126_ = item;
			_tmp127_ = objects_item_get_section_id (_tmp126_);
			_tmp128_ = _tmp127_;
			if (g_strcmp0 (_tmp128_, "") != 0) {
				JsonBuilder* _tmp129_;
				JsonBuilder* _tmp130_;
				ObjectsItem* _tmp131_;
				const gchar* _tmp132_;
				const gchar* _tmp133_;
				gchar* _tmp134_;
				gchar* _tmp135_;
				_tmp129_ = builder;
				json_builder_set_member_name (_tmp129_, "section_id");
				_tmp130_ = builder;
				_tmp131_ = item;
				_tmp132_ = objects_item_get_section_id (_tmp131_);
				_tmp133_ = _tmp132_;
				_tmp134_ = g_strconcat ("_", _tmp133_, NULL);
				_tmp135_ = _tmp134_;
				json_builder_add_string_value (_tmp130_, _tmp135_);
				_g_free0 (_tmp135_);
			}
			_tmp136_ = builder;
			json_builder_set_member_name (_tmp136_, "priority");
			_tmp138_ = item;
			_tmp139_ = objects_item_get_priority (_tmp138_);
			_tmp140_ = _tmp139_;
			if (_tmp140_ == 0) {
				_tmp137_ = CONSTANTS_PRIORITY_4;
			} else {
				ObjectsItem* _tmp141_;
				gint _tmp142_;
				gint _tmp143_;
				_tmp141_ = item;
				_tmp142_ = objects_item_get_priority (_tmp141_);
				_tmp143_ = _tmp142_;
				_tmp137_ = _tmp143_;
			}
			_tmp144_ = builder;
			json_builder_add_int_value (_tmp144_, (gint64) _tmp137_);
			_tmp145_ = item;
			_tmp146_ = objects_item_get_has_due (_tmp145_);
			_tmp147_ = _tmp146_;
			if (_tmp147_) {
				JsonBuilder* _tmp148_;
				JsonBuilder* _tmp149_;
				JsonBuilder* _tmp150_;
				JsonBuilder* _tmp151_;
				ObjectsItem* _tmp152_;
				ObjectsDueDate* _tmp153_;
				ObjectsDueDate* _tmp154_;
				gchar* _tmp155_;
				gchar* _tmp156_;
				JsonBuilder* _tmp157_;
				_tmp148_ = builder;
				json_builder_set_member_name (_tmp148_, "due");
				_tmp149_ = builder;
				json_builder_begin_object (_tmp149_);
				_tmp150_ = builder;
				json_builder_set_member_name (_tmp150_, "string");
				_tmp151_ = builder;
				_tmp152_ = item;
				_tmp153_ = objects_item_get_due (_tmp152_);
				_tmp154_ = _tmp153_;
				_tmp155_ = utils_datetime_due_to_todoist_natural_language (_tmp154_);
				_tmp156_ = _tmp155_;
				json_builder_add_string_value (_tmp151_, _tmp156_);
				_g_free0 (_tmp156_);
				_tmp157_ = builder;
				json_builder_end_object (_tmp157_);
			}
			_tmp158_ = builder;
			json_builder_set_member_name (_tmp158_, "labels");
			_tmp159_ = builder;
			json_builder_begin_array (_tmp159_);
			{
				GeeArrayList* _label_list = NULL;
				ObjectsItem* _tmp160_;
				GeeArrayList* _tmp161_;
				GeeArrayList* _tmp162_;
				gint _label_size = 0;
				GeeArrayList* _tmp163_;
				gint _tmp164_;
				gint _tmp165_;
				gint _label_index = 0;
				_tmp160_ = item;
				_tmp161_ = objects_item_get_labels (_tmp160_);
				_tmp162_ = _tmp161_;
				_label_list = _tmp162_;
				_tmp163_ = _label_list;
				_tmp164_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp163_);
				_tmp165_ = _tmp164_;
				_label_size = _tmp165_;
				_label_index = -1;
				while (TRUE) {
					gint _tmp166_;
					gint _tmp167_;
					ObjectsLabel* label = NULL;
					GeeArrayList* _tmp168_;
					gpointer _tmp169_;
					JsonBuilder* _tmp170_;
					ObjectsLabel* _tmp171_;
					const gchar* _tmp172_;
					const gchar* _tmp173_;
					_label_index = _label_index + 1;
					_tmp166_ = _label_index;
					_tmp167_ = _label_size;
					if (!(_tmp166_ < _tmp167_)) {
						break;
					}
					_tmp168_ = _label_list;
					_tmp169_ = gee_abstract_list_get ((GeeAbstractList*) _tmp168_, _label_index);
					label = (ObjectsLabel*) _tmp169_;
					_tmp170_ = builder;
					_tmp171_ = label;
					_tmp172_ = objects_base_object_get_name ((ObjectsBaseObject*) _tmp171_);
					_tmp173_ = _tmp172_;
					json_builder_add_string_value (_tmp170_, _tmp173_);
					_g_object_unref0 (label);
				}
			}
			_tmp174_ = builder;
			json_builder_end_array (_tmp174_);
			_tmp175_ = builder;
			json_builder_end_object (_tmp175_);
			_tmp176_ = builder;
			json_builder_end_object (_tmp176_);
			_g_object_unref0 (item);
		}
	}
	_tmp177_ = builder;
	json_builder_end_array (_tmp177_);
	_tmp178_ = builder;
	json_builder_end_object (_tmp178_);
	_tmp179_ = json_generator_new ();
	generator = _tmp179_;
	_tmp180_ = builder;
	_tmp181_ = json_builder_get_root (_tmp180_);
	_tmp182_ = _tmp181_;
	json_generator_set_root (generator, _tmp182_);
	__vala_JsonNode_free0 (_tmp182_);
	_tmp183_ = json_generator_to_data (generator, NULL);
	result = _tmp183_;
	_g_object_unref0 (generator);
	_g_object_unref0 (builder);
	return result;
}

static void
services_todoist_projects_class_init (ServicesTodoistProjectsClass * klass,
                                      gpointer klass_data)
{
	services_todoist_projects_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ServicesTodoistProjects_private_offset);
	G_OBJECT_CLASS (klass)->finalize = services_todoist_projects_finalize;
}

static void
services_todoist_projects_instance_init (ServicesTodoistProjects * self,
                                         gpointer klass)
{
	self->priv = services_todoist_projects_get_instance_private (self);
}

static void
services_todoist_projects_finalize (GObject * obj)
{
	ServicesTodoistProjects * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SERVICES_TYPE_TODOIST_PROJECTS, ServicesTodoistProjects);
	_g_object_unref0 (self->priv->session);
	G_OBJECT_CLASS (services_todoist_projects_parent_class)->finalize (obj);
}

static GType
services_todoist_projects_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ServicesTodoistProjectsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) services_todoist_projects_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ServicesTodoistProjects), 0, (GInstanceInitFunc) services_todoist_projects_instance_init, NULL };
	GType services_todoist_projects_type_id;
	services_todoist_projects_type_id = g_type_register_static (G_TYPE_OBJECT, "ServicesTodoistProjects", &g_define_type_info, 0);
	ServicesTodoistProjects_private_offset = g_type_add_instance_private (services_todoist_projects_type_id, sizeof (ServicesTodoistProjectsPrivate));
	return services_todoist_projects_type_id;
}

GType
services_todoist_projects_get_type (void)
{
	static volatile gsize services_todoist_projects_type_id__once = 0;
	if (g_once_init_enter (&services_todoist_projects_type_id__once)) {
		GType services_todoist_projects_type_id;
		services_todoist_projects_type_id = services_todoist_projects_get_type_once ();
		g_once_init_leave (&services_todoist_projects_type_id__once, services_todoist_projects_type_id);
	}
	return services_todoist_projects_type_id__once;
}

