/* MigrateFromPlanner.c generated by valac 0.56.19, the Vala compiler
 * generated from MigrateFromPlanner.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 <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlite3.h>
#include "planify.h"
#include <json-glib/json-glib.h>
#include <gee.h>

#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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define SERVICES_TYPE_MIGRATE_FROM_PLANNER (services_migrate_from_planner_get_type ())
#define SERVICES_MIGRATE_FROM_PLANNER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SERVICES_TYPE_MIGRATE_FROM_PLANNER, ServicesMigrateFromPlanner))
#define SERVICES_MIGRATE_FROM_PLANNER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SERVICES_TYPE_MIGRATE_FROM_PLANNER, ServicesMigrateFromPlannerClass))
#define SERVICES_IS_MIGRATE_FROM_PLANNER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SERVICES_TYPE_MIGRATE_FROM_PLANNER))
#define SERVICES_IS_MIGRATE_FROM_PLANNER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SERVICES_TYPE_MIGRATE_FROM_PLANNER))
#define SERVICES_MIGRATE_FROM_PLANNER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SERVICES_TYPE_MIGRATE_FROM_PLANNER, ServicesMigrateFromPlannerClass))

typedef struct _ServicesMigrateFromPlanner ServicesMigrateFromPlanner;
typedef struct _ServicesMigrateFromPlannerClass ServicesMigrateFromPlannerClass;
typedef struct _ServicesMigrateFromPlannerPrivate ServicesMigrateFromPlannerPrivate;
enum  {
	SERVICES_MIGRATE_FROM_PLANNER_0_PROPERTY,
	SERVICES_MIGRATE_FROM_PLANNER_NUM_PROPERTIES
};
static GParamSpec* services_migrate_from_planner_properties[SERVICES_MIGRATE_FROM_PLANNER_NUM_PROPERTIES];
#define _sqlite3_close0(var) ((var == NULL) ? NULL : (var = (sqlite3_close (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _sqlite3_finalize0(var) ((var == NULL) ? NULL : (var = (sqlite3_finalize (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))

struct _ServicesMigrateFromPlanner {
	GObject parent_instance;
	ServicesMigrateFromPlannerPrivate * priv;
};

struct _ServicesMigrateFromPlannerClass {
	GObjectClass parent_class;
};

static gpointer services_migrate_from_planner_parent_class = NULL;
static GOnce services_migrate_from_planner__instance;
static GOnce services_migrate_from_planner__instance = G_ONCE_INIT;

VALA_EXTERN GType services_migrate_from_planner_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ServicesMigrateFromPlanner, g_object_unref)
VALA_EXTERN ServicesMigrateFromPlanner* services_migrate_from_planner_get_default (void);
static ServicesMigrateFromPlanner* __lambda387_ (void);
VALA_EXTERN ServicesMigrateFromPlanner* services_migrate_from_planner_new (void);
VALA_EXTERN ServicesMigrateFromPlanner* services_migrate_from_planner_construct (GType object_type);
static gpointer ___lambda387__gthread_func (gpointer self);
VALA_EXTERN gboolean services_migrate_from_planner_migrate_from_file (ServicesMigrateFromPlanner* self,
                                                          GFile* file);
static void services_migrate_from_planner_migrate_labels (ServicesMigrateFromPlanner* self,
                                                   sqlite3* db);
static void services_migrate_from_planner_migrate_projects (ServicesMigrateFromPlanner* self,
                                                     sqlite3* db);
static void services_migrate_from_planner_migrate_sections (ServicesMigrateFromPlanner* self,
                                                     sqlite3* db);
static void services_migrate_from_planner_migrate_items (ServicesMigrateFromPlanner* self,
                                                  sqlite3* db);
static GeeArrayList* services_migrate_from_planner_get_labels_by_item (ServicesMigrateFromPlanner* self,
                                                                sqlite3* db,
                                                                const gchar* id);
static void services_migrate_from_planner_set_parameter_str (ServicesMigrateFromPlanner* self,
                                                      sqlite3_stmt* stmt,
                                                      const gchar* par,
                                                      const gchar* val);
static void services_migrate_from_planner_finalize (GObject * obj);
static GType services_migrate_from_planner_get_type_once (void);

static ServicesMigrateFromPlanner*
__lambda387_ (void)
{
	ServicesMigrateFromPlanner* _tmp0_;
	ServicesMigrateFromPlanner* result;
	_tmp0_ = services_migrate_from_planner_new ();
	result = _tmp0_;
	return result;
}

static gpointer
___lambda387__gthread_func (gpointer self)
{
	gpointer result;
	result = __lambda387_ ();
	return result;
}

ServicesMigrateFromPlanner*
services_migrate_from_planner_get_default (void)
{
	gconstpointer _tmp0_;
	ServicesMigrateFromPlanner* result;
	_tmp0_ = g_once (&services_migrate_from_planner__instance, ___lambda387__gthread_func, NULL);
	result = (ServicesMigrateFromPlanner*) _tmp0_;
	return result;
}

gboolean
services_migrate_from_planner_migrate_from_file (ServicesMigrateFromPlanner* self,
                                                 GFile* file)
{
	gchar* db_path = NULL;
	gchar* _tmp0_;
	sqlite3* db = NULL;
	sqlite3* _tmp1_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (file != NULL, FALSE);
	_tmp0_ = g_file_get_path (file);
	db_path = _tmp0_;
	sqlite3_open (db_path, &_tmp1_);
	_sqlite3_close0 (db);
	db = _tmp1_;
	services_migrate_from_planner_migrate_labels (self, db);
	services_migrate_from_planner_migrate_projects (self, db);
	services_migrate_from_planner_migrate_sections (self, db);
	services_migrate_from_planner_migrate_items (self, db);
	result = TRUE;
	_sqlite3_close0 (db);
	_g_free0 (db_path);
	return result;
}

static void
services_migrate_from_planner_migrate_labels (ServicesMigrateFromPlanner* self,
                                              sqlite3* db)
{
	sqlite3_stmt* stmt = NULL;
	gchar* sql = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	sqlite3_stmt* _tmp5_ = NULL;
	sqlite3_stmt* _tmp24_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = g_strdup ("\n            SELECT * FROM Labels where todoist = 0;\n        ");
	sql = _tmp0_;
	_tmp1_ = sql;
	_tmp2_ = sql;
	_tmp3_ = strlen (_tmp2_);
	_tmp4_ = _tmp3_;
	sqlite3_prepare_v2 (db, _tmp1_, _tmp4_, &_tmp5_, NULL);
	_sqlite3_finalize0 (stmt);
	stmt = _tmp5_;
	while (TRUE) {
		sqlite3_stmt* _tmp6_;
		ObjectsLabel* label = NULL;
		ObjectsLabel* _tmp7_;
		ObjectsLabel* _tmp8_;
		sqlite3_stmt* _tmp9_;
		const gchar* _tmp10_;
		ObjectsLabel* _tmp11_;
		sqlite3_stmt* _tmp12_;
		const gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		ObjectsLabel* _tmp16_;
		sqlite3_stmt* _tmp17_;
		const gchar* _tmp18_;
		ObjectsLabel* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		ServicesStore* _tmp22_;
		ObjectsLabel* _tmp23_;
		_tmp6_ = stmt;
		if (!(sqlite3_step (_tmp6_) == SQLITE_ROW)) {
			break;
		}
		_tmp7_ = objects_label_new ();
		label = _tmp7_;
		_tmp8_ = label;
		_tmp9_ = stmt;
		_tmp10_ = (const gchar*) sqlite3_column_text (_tmp9_, 0);
		objects_base_object_set_id ((ObjectsBaseObject*) _tmp8_, _tmp10_);
		_tmp11_ = label;
		_tmp12_ = stmt;
		_tmp13_ = (const gchar*) sqlite3_column_text (_tmp12_, 1);
		_tmp14_ = g_strdup_printf ("(Planner) %s", _tmp13_);
		_tmp15_ = _tmp14_;
		objects_base_object_set_name ((ObjectsBaseObject*) _tmp11_, _tmp15_);
		_g_free0 (_tmp15_);
		_tmp16_ = label;
		_tmp17_ = stmt;
		_tmp18_ = (const gchar*) sqlite3_column_text (_tmp17_, 2);
		objects_base_object_set_color ((ObjectsBaseObject*) _tmp16_, _tmp18_);
		_tmp19_ = label;
		_tmp20_ = source_type_to_string (SOURCE_TYPE_LOCAL);
		_tmp21_ = _tmp20_;
		objects_label_set_source_id (_tmp19_, _tmp21_);
		_g_free0 (_tmp21_);
		_tmp22_ = services_store_instance ();
		_tmp23_ = label;
		services_store_insert_label (_tmp22_, _tmp23_);
		_g_object_unref0 (label);
	}
	_tmp24_ = stmt;
	sqlite3_reset (_tmp24_);
	_g_free0 (sql);
	_sqlite3_finalize0 (stmt);
}

static void
services_migrate_from_planner_migrate_projects (ServicesMigrateFromPlanner* self,
                                                sqlite3* db)
{
	sqlite3_stmt* stmt = NULL;
	gchar* sql = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	sqlite3_stmt* _tmp5_ = NULL;
	sqlite3_stmt* _tmp24_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = g_strdup ("\n            SELECT * FROM Projects WHERE todoist = 0;\n        ");
	sql = _tmp0_;
	_tmp1_ = sql;
	_tmp2_ = sql;
	_tmp3_ = strlen (_tmp2_);
	_tmp4_ = _tmp3_;
	sqlite3_prepare_v2 (db, _tmp1_, _tmp4_, &_tmp5_, NULL);
	_sqlite3_finalize0 (stmt);
	stmt = _tmp5_;
	while (TRUE) {
		sqlite3_stmt* _tmp6_;
		ObjectsProject* project = NULL;
		ObjectsProject* _tmp7_;
		ObjectsProject* _tmp8_;
		sqlite3_stmt* _tmp9_;
		const gchar* _tmp10_;
		ObjectsProject* _tmp11_;
		sqlite3_stmt* _tmp12_;
		const gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		ObjectsProject* _tmp16_;
		sqlite3_stmt* _tmp17_;
		const gchar* _tmp18_;
		ObjectsProject* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		ServicesStore* _tmp22_;
		ObjectsProject* _tmp23_;
		_tmp6_ = stmt;
		if (!(sqlite3_step (_tmp6_) == SQLITE_ROW)) {
			break;
		}
		_tmp7_ = objects_project_new ();
		project = _tmp7_;
		_tmp8_ = project;
		_tmp9_ = stmt;
		_tmp10_ = (const gchar*) sqlite3_column_text (_tmp9_, 0);
		objects_base_object_set_id ((ObjectsBaseObject*) _tmp8_, _tmp10_);
		_tmp11_ = project;
		_tmp12_ = stmt;
		_tmp13_ = (const gchar*) sqlite3_column_text (_tmp12_, 1);
		_tmp14_ = g_strdup_printf ("(Planner) %s", _tmp13_);
		_tmp15_ = _tmp14_;
		objects_base_object_set_name ((ObjectsBaseObject*) _tmp11_, _tmp15_);
		_g_free0 (_tmp15_);
		_tmp16_ = project;
		_tmp17_ = stmt;
		_tmp18_ = (const gchar*) sqlite3_column_text (_tmp17_, 2);
		objects_base_object_set_color ((ObjectsBaseObject*) _tmp16_, _tmp18_);
		_tmp19_ = project;
		_tmp20_ = source_type_to_string (SOURCE_TYPE_LOCAL);
		_tmp21_ = _tmp20_;
		objects_project_set_source_id (_tmp19_, _tmp21_);
		_g_free0 (_tmp21_);
		_tmp22_ = services_store_instance ();
		_tmp23_ = project;
		services_store_insert_project (_tmp22_, _tmp23_);
		_g_object_unref0 (project);
	}
	_tmp24_ = stmt;
	sqlite3_reset (_tmp24_);
	_g_free0 (sql);
	_sqlite3_finalize0 (stmt);
}

static void
services_migrate_from_planner_migrate_sections (ServicesMigrateFromPlanner* self,
                                                sqlite3* db)
{
	sqlite3_stmt* stmt = NULL;
	gchar* sql = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	sqlite3_stmt* _tmp5_ = NULL;
	sqlite3_stmt* _tmp27_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = g_strdup ("\n            SELECT * FROM Sections;\n        ");
	sql = _tmp0_;
	_tmp1_ = sql;
	_tmp2_ = sql;
	_tmp3_ = strlen (_tmp2_);
	_tmp4_ = _tmp3_;
	sqlite3_prepare_v2 (db, _tmp1_, _tmp4_, &_tmp5_, NULL);
	_sqlite3_finalize0 (stmt);
	stmt = _tmp5_;
	while (TRUE) {
		sqlite3_stmt* _tmp6_;
		ObjectsSection* section = NULL;
		ObjectsSection* _tmp7_;
		ObjectsSection* _tmp8_;
		sqlite3_stmt* _tmp9_;
		const gchar* _tmp10_;
		ObjectsSection* _tmp11_;
		sqlite3_stmt* _tmp12_;
		const gchar* _tmp13_;
		ObjectsSection* _tmp14_;
		sqlite3_stmt* _tmp15_;
		const gchar* _tmp16_;
		ObjectsProject* project = NULL;
		ServicesStore* _tmp17_;
		ObjectsSection* _tmp18_;
		const gchar* _tmp19_;
		const gchar* _tmp20_;
		ObjectsProject* _tmp21_;
		ObjectsProject* _tmp22_;
		_tmp6_ = stmt;
		if (!(sqlite3_step (_tmp6_) == SQLITE_ROW)) {
			break;
		}
		_tmp7_ = objects_section_new ();
		section = _tmp7_;
		_tmp8_ = section;
		_tmp9_ = stmt;
		_tmp10_ = (const gchar*) sqlite3_column_text (_tmp9_, 0);
		objects_base_object_set_id ((ObjectsBaseObject*) _tmp8_, _tmp10_);
		_tmp11_ = section;
		_tmp12_ = stmt;
		_tmp13_ = (const gchar*) sqlite3_column_text (_tmp12_, 1);
		objects_base_object_set_name ((ObjectsBaseObject*) _tmp11_, _tmp13_);
		_tmp14_ = section;
		_tmp15_ = stmt;
		_tmp16_ = (const gchar*) sqlite3_column_text (_tmp15_, 4);
		objects_section_set_project_id (_tmp14_, _tmp16_);
		_tmp17_ = services_store_instance ();
		_tmp18_ = section;
		_tmp19_ = objects_section_get_project_id (_tmp18_);
		_tmp20_ = _tmp19_;
		_tmp21_ = services_store_get_project (_tmp17_, _tmp20_);
		project = _tmp21_;
		_tmp22_ = project;
		if (_tmp22_ != NULL) {
			ObjectsProject* _tmp23_;
			ObjectsSection* _tmp24_;
			ObjectsSection* _tmp25_;
			ObjectsSection* _tmp26_;
			_tmp23_ = project;
			_tmp24_ = section;
			_tmp25_ = objects_project_add_section_if_not_exists (_tmp23_, _tmp24_);
			_tmp26_ = _tmp25_;
			_g_object_unref0 (_tmp26_);
		}
		_g_object_unref0 (project);
		_g_object_unref0 (section);
	}
	_tmp27_ = stmt;
	sqlite3_reset (_tmp27_);
	_g_free0 (sql);
	_sqlite3_finalize0 (stmt);
}

static void
services_migrate_from_planner_migrate_items (ServicesMigrateFromPlanner* self,
                                             sqlite3* db)
{
	sqlite3_stmt* stmt = NULL;
	gchar* sql = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	sqlite3_stmt* _tmp5_ = NULL;
	sqlite3_stmt* _tmp89_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (db != NULL);
	_tmp0_ = g_strdup ("\n            SELECT * FROM Items;\n        ");
	sql = _tmp0_;
	_tmp1_ = sql;
	_tmp2_ = sql;
	_tmp3_ = strlen (_tmp2_);
	_tmp4_ = _tmp3_;
	sqlite3_prepare_v2 (db, _tmp1_, _tmp4_, &_tmp5_, NULL);
	_sqlite3_finalize0 (stmt);
	stmt = _tmp5_;
	while (TRUE) {
		sqlite3_stmt* _tmp6_;
		ObjectsItem* item = NULL;
		ObjectsItem* _tmp7_;
		ObjectsItem* _tmp8_;
		sqlite3_stmt* _tmp9_;
		const gchar* _tmp10_;
		ObjectsItem* _tmp11_;
		sqlite3_stmt* _tmp12_;
		const gchar* _tmp13_;
		ObjectsItem* _tmp14_;
		sqlite3_stmt* _tmp15_;
		const gchar* _tmp16_;
		ObjectsItem* _tmp17_;
		ObjectsDueDate* _tmp18_;
		ObjectsDueDate* _tmp19_;
		ServicesDatabase* _tmp20_;
		ServicesDatabase* _tmp21_;
		sqlite3_stmt* _tmp22_;
		const gchar* _tmp23_;
		JsonObject* _tmp24_;
		JsonObject* _tmp25_;
		const gchar* _tmp26_ = NULL;
		sqlite3_stmt* _tmp27_;
		const gchar* _tmp28_;
		ObjectsItem* _tmp31_;
		ObjectsItem* _tmp32_;
		sqlite3_stmt* _tmp33_;
		const gchar* _tmp34_;
		const gchar* _tmp35_ = NULL;
		sqlite3_stmt* _tmp36_;
		const gchar* _tmp37_;
		ObjectsItem* _tmp40_;
		ObjectsItem* _tmp41_;
		sqlite3_stmt* _tmp42_;
		ObjectsItem* _tmp43_;
		sqlite3_stmt* _tmp44_;
		ObjectsItem* _tmp45_;
		sqlite3_stmt* _tmp46_;
		ObjectsItem* _tmp47_;
		ObjectsItem* _tmp48_;
		const gchar* _tmp49_;
		const gchar* _tmp50_;
		GeeArrayList* _tmp51_;
		GeeArrayList* _tmp52_;
		ObjectsItem* _tmp53_;
		const gchar* _tmp54_;
		const gchar* _tmp55_;
		_tmp6_ = stmt;
		if (!(sqlite3_step (_tmp6_) == SQLITE_ROW)) {
			break;
		}
		_tmp7_ = objects_item_new ();
		item = _tmp7_;
		_tmp8_ = item;
		_tmp9_ = stmt;
		_tmp10_ = (const gchar*) sqlite3_column_text (_tmp9_, 0);
		objects_base_object_set_id ((ObjectsBaseObject*) _tmp8_, _tmp10_);
		_tmp11_ = item;
		_tmp12_ = stmt;
		_tmp13_ = (const gchar*) sqlite3_column_text (_tmp12_, 1);
		objects_item_set_content (_tmp11_, _tmp13_);
		_tmp14_ = item;
		_tmp15_ = stmt;
		_tmp16_ = (const gchar*) sqlite3_column_text (_tmp15_, 2);
		objects_item_set_description (_tmp14_, _tmp16_);
		_tmp17_ = item;
		_tmp18_ = objects_item_get_due (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = services_database_get_default ();
		_tmp21_ = _tmp20_;
		_tmp22_ = stmt;
		_tmp23_ = (const gchar*) sqlite3_column_text (_tmp22_, 3);
		_tmp24_ = services_database_get_due_parameter (_tmp21_, _tmp23_);
		_tmp25_ = _tmp24_;
		objects_due_date_update_from_json (_tmp19_, _tmp25_);
		_json_object_unref0 (_tmp25_);
		_g_object_unref0 (_tmp21_);
		_tmp27_ = stmt;
		_tmp28_ = (const gchar*) sqlite3_column_text (_tmp27_, 7);
		if (g_strcmp0 (_tmp28_, "0") == 0) {
			_tmp26_ = "";
		} else {
			sqlite3_stmt* _tmp29_;
			const gchar* _tmp30_;
			_tmp29_ = stmt;
			_tmp30_ = (const gchar*) sqlite3_column_text (_tmp29_, 7);
			_tmp26_ = _tmp30_;
		}
		_tmp31_ = item;
		objects_item_set_section_id (_tmp31_, _tmp26_);
		_tmp32_ = item;
		_tmp33_ = stmt;
		_tmp34_ = (const gchar*) sqlite3_column_text (_tmp33_, 8);
		objects_item_set_project_id (_tmp32_, _tmp34_);
		_tmp36_ = stmt;
		_tmp37_ = (const gchar*) sqlite3_column_text (_tmp36_, 9);
		if (g_strcmp0 (_tmp37_, "0") == 0) {
			_tmp35_ = "";
		} else {
			sqlite3_stmt* _tmp38_;
			const gchar* _tmp39_;
			_tmp38_ = stmt;
			_tmp39_ = (const gchar*) sqlite3_column_text (_tmp38_, 9);
			_tmp35_ = _tmp39_;
		}
		_tmp40_ = item;
		objects_item_set_parent_id (_tmp40_, _tmp35_);
		_tmp41_ = item;
		_tmp42_ = stmt;
		objects_item_set_priority (_tmp41_, sqlite3_column_int (_tmp42_, 10));
		_tmp43_ = item;
		_tmp44_ = stmt;
		objects_item_set_checked (_tmp43_, sqlite3_column_int (_tmp44_, 12) == 1);
		_tmp45_ = item;
		_tmp46_ = stmt;
		objects_item_set_pinned (_tmp45_, sqlite3_column_int (_tmp46_, 16) == 1);
		_tmp47_ = item;
		_tmp48_ = item;
		_tmp49_ = objects_base_object_get_id ((ObjectsBaseObject*) _tmp48_);
		_tmp50_ = _tmp49_;
		_tmp51_ = services_migrate_from_planner_get_labels_by_item (self, db, _tmp50_);
		_tmp52_ = _tmp51_;
		objects_item_set_labels (_tmp47_, _tmp52_);
		_g_object_unref0 (_tmp52_);
		_tmp53_ = item;
		_tmp54_ = objects_item_get_parent_id (_tmp53_);
		_tmp55_ = _tmp54_;
		if (g_strcmp0 (_tmp55_, "") != 0) {
			ObjectsItem* parent_item = NULL;
			ServicesStore* _tmp56_;
			ObjectsItem* _tmp57_;
			const gchar* _tmp58_;
			const gchar* _tmp59_;
			ObjectsItem* _tmp60_;
			ObjectsItem* _tmp61_;
			_tmp56_ = services_store_instance ();
			_tmp57_ = item;
			_tmp58_ = objects_item_get_parent_id (_tmp57_);
			_tmp59_ = _tmp58_;
			_tmp60_ = services_store_get_item (_tmp56_, _tmp59_);
			parent_item = _tmp60_;
			_tmp61_ = parent_item;
			if (_tmp61_ != NULL) {
				ObjectsItem* _tmp62_;
				ObjectsItem* _tmp63_;
				ObjectsItem* _tmp64_;
				ObjectsItem* _tmp65_;
				_tmp62_ = parent_item;
				_tmp63_ = item;
				_tmp64_ = objects_item_add_item_if_not_exists (_tmp62_, _tmp63_, TRUE);
				_tmp65_ = _tmp64_;
				_g_object_unref0 (_tmp65_);
			}
			_g_object_unref0 (parent_item);
		} else {
			ObjectsItem* _tmp66_;
			const gchar* _tmp67_;
			const gchar* _tmp68_;
			_tmp66_ = item;
			_tmp67_ = objects_item_get_section_id (_tmp66_);
			_tmp68_ = _tmp67_;
			if (g_strcmp0 (_tmp68_, "") != 0) {
				ObjectsSection* section = NULL;
				ServicesStore* _tmp69_;
				ObjectsItem* _tmp70_;
				const gchar* _tmp71_;
				const gchar* _tmp72_;
				ObjectsSection* _tmp73_;
				ObjectsSection* _tmp74_;
				_tmp69_ = services_store_instance ();
				_tmp70_ = item;
				_tmp71_ = objects_item_get_section_id (_tmp70_);
				_tmp72_ = _tmp71_;
				_tmp73_ = services_store_get_section (_tmp69_, _tmp72_);
				section = _tmp73_;
				_tmp74_ = section;
				if (_tmp74_ != NULL) {
					ObjectsSection* _tmp75_;
					ObjectsItem* _tmp76_;
					ObjectsItem* _tmp77_;
					ObjectsItem* _tmp78_;
					_tmp75_ = section;
					_tmp76_ = item;
					_tmp77_ = objects_section_add_item_if_not_exists (_tmp75_, _tmp76_, TRUE);
					_tmp78_ = _tmp77_;
					_g_object_unref0 (_tmp78_);
				}
				_g_object_unref0 (section);
			} else {
				ObjectsProject* project = NULL;
				ServicesStore* _tmp79_;
				ObjectsItem* _tmp80_;
				const gchar* _tmp81_;
				const gchar* _tmp82_;
				ObjectsProject* _tmp83_;
				ObjectsProject* _tmp84_;
				_tmp79_ = services_store_instance ();
				_tmp80_ = item;
				_tmp81_ = objects_item_get_project_id (_tmp80_);
				_tmp82_ = _tmp81_;
				_tmp83_ = services_store_get_project (_tmp79_, _tmp82_);
				project = _tmp83_;
				_tmp84_ = project;
				if (_tmp84_ != NULL) {
					ObjectsProject* _tmp85_;
					ObjectsItem* _tmp86_;
					ObjectsItem* _tmp87_;
					ObjectsItem* _tmp88_;
					_tmp85_ = project;
					_tmp86_ = item;
					_tmp87_ = objects_project_add_item_if_not_exists (_tmp85_, _tmp86_, TRUE);
					_tmp88_ = _tmp87_;
					_g_object_unref0 (_tmp88_);
				}
				_g_object_unref0 (project);
			}
		}
		_g_object_unref0 (item);
	}
	_tmp89_ = stmt;
	sqlite3_reset (_tmp89_);
	_g_free0 (sql);
	_sqlite3_finalize0 (stmt);
}

static GeeArrayList*
services_migrate_from_planner_get_labels_by_item (ServicesMigrateFromPlanner* self,
                                                  sqlite3* db,
                                                  const gchar* id)
{
	GeeArrayList* return_value = NULL;
	GeeArrayList* _tmp0_;
	sqlite3_stmt* stmt = NULL;
	gchar* sql = NULL;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	sqlite3_stmt* _tmp6_ = NULL;
	sqlite3_stmt* _tmp7_;
	GeeArrayList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	g_return_val_if_fail (id != NULL, NULL);
	_tmp0_ = gee_array_list_new (OBJECTS_TYPE_LABEL, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	return_value = _tmp0_;
	_tmp1_ = g_strdup ("\n" \
"            SELECT * FROM Items_Labels WHERE item_id = $item_id;\n" \
"        ");
	sql = _tmp1_;
	_tmp2_ = sql;
	_tmp3_ = sql;
	_tmp4_ = strlen (_tmp3_);
	_tmp5_ = _tmp4_;
	sqlite3_prepare_v2 (db, _tmp2_, _tmp5_, &_tmp6_, NULL);
	_sqlite3_finalize0 (stmt);
	stmt = _tmp6_;
	_tmp7_ = stmt;
	services_migrate_from_planner_set_parameter_str (self, _tmp7_, "$item_id", id);
	while (TRUE) {
		sqlite3_stmt* _tmp8_;
		ObjectsLabel* label = NULL;
		ServicesStore* _tmp9_;
		sqlite3_stmt* _tmp10_;
		const gchar* _tmp11_;
		ObjectsLabel* _tmp12_;
		ObjectsLabel* _tmp13_;
		_tmp8_ = stmt;
		if (!(sqlite3_step (_tmp8_) == SQLITE_ROW)) {
			break;
		}
		_tmp9_ = services_store_instance ();
		_tmp10_ = stmt;
		_tmp11_ = (const gchar*) sqlite3_column_text (_tmp10_, 2);
		_tmp12_ = services_store_get_label (_tmp9_, _tmp11_);
		label = _tmp12_;
		_tmp13_ = label;
		if (_tmp13_ != NULL) {
			GeeArrayList* _tmp14_;
			ObjectsLabel* _tmp15_;
			_tmp14_ = return_value;
			_tmp15_ = label;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp14_, _tmp15_);
		}
		_g_object_unref0 (label);
	}
	result = return_value;
	_g_free0 (sql);
	_sqlite3_finalize0 (stmt);
	return result;
}

static void
services_migrate_from_planner_set_parameter_str (ServicesMigrateFromPlanner* self,
                                                 sqlite3_stmt* stmt,
                                                 const gchar* par,
                                                 const gchar* val)
{
	gint par_position = 0;
	gchar* _tmp0_;
	GDestroyNotify _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (par != NULL);
	g_return_if_fail (val != NULL);
	par_position = sqlite3_bind_parameter_index (stmt, par);
	_tmp0_ = g_strdup (val);
	_tmp1_ = g_free;
	sqlite3_bind_text (stmt, par_position, _tmp0_, -1, _tmp1_);
}

ServicesMigrateFromPlanner*
services_migrate_from_planner_construct (GType object_type)
{
	ServicesMigrateFromPlanner * self = NULL;
	self = (ServicesMigrateFromPlanner*) g_object_new (object_type, NULL);
	return self;
}

ServicesMigrateFromPlanner*
services_migrate_from_planner_new (void)
{
	return services_migrate_from_planner_construct (SERVICES_TYPE_MIGRATE_FROM_PLANNER);
}

static void
services_migrate_from_planner_class_init (ServicesMigrateFromPlannerClass * klass,
                                          gpointer klass_data)
{
	services_migrate_from_planner_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = services_migrate_from_planner_finalize;
}

static void
services_migrate_from_planner_instance_init (ServicesMigrateFromPlanner * self,
                                             gpointer klass)
{
}

static void
services_migrate_from_planner_finalize (GObject * obj)
{
	ServicesMigrateFromPlanner * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SERVICES_TYPE_MIGRATE_FROM_PLANNER, ServicesMigrateFromPlanner);
	G_OBJECT_CLASS (services_migrate_from_planner_parent_class)->finalize (obj);
}

static GType
services_migrate_from_planner_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ServicesMigrateFromPlannerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) services_migrate_from_planner_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ServicesMigrateFromPlanner), 0, (GInstanceInitFunc) services_migrate_from_planner_instance_init, NULL };
	GType services_migrate_from_planner_type_id;
	services_migrate_from_planner_type_id = g_type_register_static (G_TYPE_OBJECT, "ServicesMigrateFromPlanner", &g_define_type_info, 0);
	return services_migrate_from_planner_type_id;
}

GType
services_migrate_from_planner_get_type (void)
{
	static volatile gsize services_migrate_from_planner_type_id__once = 0;
	if (g_once_init_enter (&services_migrate_from_planner_type_id__once)) {
		GType services_migrate_from_planner_type_id;
		services_migrate_from_planner_type_id = services_migrate_from_planner_get_type_once ();
		g_once_init_leave (&services_migrate_from_planner_type_id__once, services_migrate_from_planner_type_id);
	}
	return services_migrate_from_planner_type_id__once;
}

