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

/*
 * Copyright © 2026 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
 */

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "planify.h"
#include <gee.h>
#include <gio/gio.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 PLANIFY_CLI_TYPE_TASK_CREATOR (planify_cli_task_creator_get_type ())
#define PLANIFY_CLI_TASK_CREATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLANIFY_CLI_TYPE_TASK_CREATOR, PlanifyCLITaskCreator))
#define PLANIFY_CLI_TASK_CREATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PLANIFY_CLI_TYPE_TASK_CREATOR, PlanifyCLITaskCreatorClass))
#define PLANIFY_CLI_IS_TASK_CREATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PLANIFY_CLI_TYPE_TASK_CREATOR))
#define PLANIFY_CLI_IS_TASK_CREATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PLANIFY_CLI_TYPE_TASK_CREATOR))
#define PLANIFY_CLI_TASK_CREATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PLANIFY_CLI_TYPE_TASK_CREATOR, PlanifyCLITaskCreatorClass))

typedef struct _PlanifyCLITaskCreator PlanifyCLITaskCreator;
typedef struct _PlanifyCLITaskCreatorClass PlanifyCLITaskCreatorClass;
typedef struct _PlanifyCLITaskCreatorPrivate PlanifyCLITaskCreatorPrivate;
enum  {
	PLANIFY_CLI_TASK_CREATOR_0_PROPERTY,
	PLANIFY_CLI_TASK_CREATOR_NUM_PROPERTIES
};
static GParamSpec* planify_cli_task_creator_properties[PLANIFY_CLI_TASK_CREATOR_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))

#define TYPE_DBUS_CLIENT (dbus_client_get_type ())
#define DBUS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DBUS_CLIENT, DBusClient))
#define DBUS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DBUS_CLIENT, DBusClientClass))
#define IS_DBUS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DBUS_CLIENT))
#define IS_DBUS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DBUS_CLIENT))
#define DBUS_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DBUS_CLIENT, DBusClientClass))

typedef struct _DBusClient DBusClient;
typedef struct _DBusClientClass DBusClientClass;
typedef struct _DBusClientPrivate DBusClientPrivate;

#define TYPE_DBUS_CLIENT_INTERFACE (dbus_client_interface_get_type ())
#define DBUS_CLIENT_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DBUS_CLIENT_INTERFACE, DBusClientInterface))
#define IS_DBUS_CLIENT_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DBUS_CLIENT_INTERFACE))
#define DBUS_CLIENT_INTERFACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_DBUS_CLIENT_INTERFACE, DBusClientInterfaceIface))

typedef struct _DBusClientInterface DBusClientInterface;
typedef struct _DBusClientInterfaceIface DBusClientInterfaceIface;

#define TYPE_DBUS_CLIENT_INTERFACE_PROXY (dbus_client_interface_proxy_get_type ())
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_main_context_unref0(var) ((var == NULL) ? NULL : (var = (g_main_context_unref (var), NULL)))

struct _PlanifyCLITaskCreator {
	GObject parent_instance;
	PlanifyCLITaskCreatorPrivate * priv;
};

struct _PlanifyCLITaskCreatorClass {
	GObjectClass parent_class;
};

struct _DBusClientInterfaceIface {
	GTypeInterface parent_iface;
	void (*add_item) (DBusClientInterface* self, const gchar* id, GError** error);
	void (*update_item) (DBusClientInterface* self, const gchar* id, GError** error);
};

struct _DBusClient {
	GObject parent_instance;
	DBusClientPrivate * priv;
	DBusClientInterface* interface;
};

struct _DBusClientClass {
	GObjectClass parent_class;
};

static gpointer planify_cli_task_creator_parent_class = NULL;

VALA_EXTERN GType planify_cli_task_creator_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PlanifyCLITaskCreator, g_object_unref)
VALA_EXTERN ObjectsSection* planify_cli_task_creator_find_section (const gchar* section_id,
                                                       const gchar* section_name,
                                                       ObjectsProject* project,
                                                       gchar** error_message);
VALA_EXTERN ObjectsProject* planify_cli_task_creator_find_project (const gchar* project_id,
                                                       const gchar* project_name,
                                                       gchar** error_message);
VALA_EXTERN ObjectsItem* planify_cli_task_creator_create_item (const gchar* content,
                                                   const gchar* description,
                                                   gint priority,
                                                   GDateTime* due_datetime,
                                                   ObjectsProject* project,
                                                   const gchar* parent_id);
VALA_EXTERN gboolean planify_cli_task_creator_save_and_notify (ObjectsItem* item);
VALA_EXTERN GType dbus_client_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DBusClient, g_object_unref)
VALA_EXTERN DBusClient* dbus_client_get_default (void);
VALA_EXTERN GType dbus_client_interface_proxy_get_type (void) G_GNUC_CONST ;
VALA_EXTERN guint dbus_client_interface_register_object (void* object,
                                             GDBusConnection* connection,
                                             const gchar* path,
                                             GError** error);
VALA_EXTERN GType dbus_client_interface_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DBusClientInterface, g_object_unref)
VALA_EXTERN void dbus_client_interface_add_item (DBusClientInterface* self,
                                     const gchar* id,
                                     GError** error);
VALA_EXTERN PlanifyCLITaskCreator* planify_cli_task_creator_new (void);
VALA_EXTERN PlanifyCLITaskCreator* planify_cli_task_creator_construct (GType object_type);
static GType planify_cli_task_creator_get_type_once (void);

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

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

ObjectsSection*
planify_cli_task_creator_find_section (const gchar* section_id,
                                       const gchar* section_name,
                                       ObjectsProject* project,
                                       gchar** error_message)
{
	gchar* _vala_error_message = NULL;
	ObjectsSection* target_section = NULL;
	gboolean _tmp0_ = FALSE;
	ObjectsSection* result;
	g_return_val_if_fail (project != NULL, NULL);
	_g_free0 (_vala_error_message);
	_vala_error_message = NULL;
	target_section = NULL;
	if (section_id != NULL) {
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = string_strip (section_id);
		_tmp2_ = _tmp1_;
		_tmp0_ = g_strcmp0 (_tmp2_, "") != 0;
		_g_free0 (_tmp2_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		ObjectsSection* _tmp20_;
		{
			GeeArrayList* _section_list = NULL;
			ServicesStore* _tmp3_;
			GeeArrayList* _tmp4_;
			gint _section_size = 0;
			GeeArrayList* _tmp5_;
			gint _tmp6_;
			gint _tmp7_;
			gint _section_index = 0;
			_tmp3_ = services_store_instance ();
			_tmp4_ = services_store_get_sections_by_project (_tmp3_, project);
			_section_list = _tmp4_;
			_tmp5_ = _section_list;
			_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
			_tmp7_ = _tmp6_;
			_section_size = _tmp7_;
			_section_index = -1;
			while (TRUE) {
				gint _tmp8_;
				gint _tmp9_;
				ObjectsSection* section = NULL;
				GeeArrayList* _tmp10_;
				gpointer _tmp11_;
				ObjectsSection* _tmp12_;
				const gchar* _tmp13_;
				const gchar* _tmp14_;
				gchar* _tmp15_;
				gchar* _tmp16_;
				gboolean _tmp17_;
				_section_index = _section_index + 1;
				_tmp8_ = _section_index;
				_tmp9_ = _section_size;
				if (!(_tmp8_ < _tmp9_)) {
					break;
				}
				_tmp10_ = _section_list;
				_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, _section_index);
				section = (ObjectsSection*) _tmp11_;
				_tmp12_ = section;
				_tmp13_ = objects_base_object_get_id ((ObjectsBaseObject*) _tmp12_);
				_tmp14_ = _tmp13_;
				_tmp15_ = string_strip (section_id);
				_tmp16_ = _tmp15_;
				_tmp17_ = g_strcmp0 (_tmp14_, _tmp16_) == 0;
				_g_free0 (_tmp16_);
				if (_tmp17_) {
					ObjectsSection* _tmp18_;
					ObjectsSection* _tmp19_;
					_tmp18_ = section;
					_tmp19_ = _g_object_ref0 (_tmp18_);
					_g_object_unref0 (target_section);
					target_section = _tmp19_;
					_g_object_unref0 (section);
					break;
				}
				_g_object_unref0 (section);
			}
			_g_object_unref0 (_section_list);
		}
		_tmp20_ = target_section;
		if (_tmp20_ == NULL) {
			const gchar* _tmp21_;
			const gchar* _tmp22_;
			gchar* _tmp23_;
			_tmp21_ = objects_base_object_get_name ((ObjectsBaseObject*) project);
			_tmp22_ = _tmp21_;
			_tmp23_ = g_strdup_printf ("Error: Section ID '%s' not found in project '%s'", section_id, _tmp22_);
			_g_free0 (_vala_error_message);
			_vala_error_message = _tmp23_;
			result = NULL;
			_g_object_unref0 (target_section);
			if (error_message) {
				*error_message = _vala_error_message;
			} else {
				_g_free0 (_vala_error_message);
			}
			return result;
		}
	} else {
		gboolean _tmp24_ = FALSE;
		if (section_name != NULL) {
			gchar* _tmp25_;
			gchar* _tmp26_;
			_tmp25_ = string_strip (section_name);
			_tmp26_ = _tmp25_;
			_tmp24_ = g_strcmp0 (_tmp26_, "") != 0;
			_g_free0 (_tmp26_);
		} else {
			_tmp24_ = FALSE;
		}
		if (_tmp24_) {
			gchar* search_name = NULL;
			gchar* _tmp27_;
			gchar* _tmp28_;
			gchar* _tmp29_;
			gchar* _tmp30_;
			ObjectsSection* _tmp49_;
			_tmp27_ = string_strip (section_name);
			_tmp28_ = _tmp27_;
			_tmp29_ = g_utf8_strdown (_tmp28_, (gssize) -1);
			_tmp30_ = _tmp29_;
			_g_free0 (_tmp28_);
			search_name = _tmp30_;
			{
				GeeArrayList* _section_list = NULL;
				ServicesStore* _tmp31_;
				GeeArrayList* _tmp32_;
				gint _section_size = 0;
				GeeArrayList* _tmp33_;
				gint _tmp34_;
				gint _tmp35_;
				gint _section_index = 0;
				_tmp31_ = services_store_instance ();
				_tmp32_ = services_store_get_sections_by_project (_tmp31_, project);
				_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_;
					ObjectsSection* _tmp40_;
					const gchar* _tmp41_;
					const gchar* _tmp42_;
					gchar* _tmp43_;
					gchar* _tmp44_;
					const gchar* _tmp45_;
					gboolean _tmp46_;
					_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_ = section;
					_tmp41_ = objects_base_object_get_name ((ObjectsBaseObject*) _tmp40_);
					_tmp42_ = _tmp41_;
					_tmp43_ = g_utf8_strdown (_tmp42_, (gssize) -1);
					_tmp44_ = _tmp43_;
					_tmp45_ = search_name;
					_tmp46_ = g_strcmp0 (_tmp44_, _tmp45_) == 0;
					_g_free0 (_tmp44_);
					if (_tmp46_) {
						ObjectsSection* _tmp47_;
						ObjectsSection* _tmp48_;
						_tmp47_ = section;
						_tmp48_ = _g_object_ref0 (_tmp47_);
						_g_object_unref0 (target_section);
						target_section = _tmp48_;
						_g_object_unref0 (section);
						break;
					}
					_g_object_unref0 (section);
				}
				_g_object_unref0 (_section_list);
			}
			_tmp49_ = target_section;
			if (_tmp49_ == NULL) {
				const gchar* _tmp50_;
				const gchar* _tmp51_;
				gchar* _tmp52_;
				_tmp50_ = objects_base_object_get_name ((ObjectsBaseObject*) project);
				_tmp51_ = _tmp50_;
				_tmp52_ = g_strdup_printf ("Error: Section '%s' not found in project '%s'", section_name, _tmp51_);
				_g_free0 (_vala_error_message);
				_vala_error_message = _tmp52_;
				result = NULL;
				_g_free0 (search_name);
				_g_object_unref0 (target_section);
				if (error_message) {
					*error_message = _vala_error_message;
				} else {
					_g_free0 (_vala_error_message);
				}
				return result;
			}
			_g_free0 (search_name);
		}
	}
	result = target_section;
	if (error_message) {
		*error_message = _vala_error_message;
	} else {
		_g_free0 (_vala_error_message);
	}
	return result;
}

ObjectsProject*
planify_cli_task_creator_find_project (const gchar* project_id,
                                       const gchar* project_name,
                                       gchar** error_message)
{
	gchar* _vala_error_message = NULL;
	ObjectsProject* target_project = NULL;
	gboolean _tmp0_ = FALSE;
	ObjectsProject* result;
	_g_free0 (_vala_error_message);
	_vala_error_message = NULL;
	target_project = NULL;
	if (project_id != NULL) {
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = string_strip (project_id);
		_tmp2_ = _tmp1_;
		_tmp0_ = g_strcmp0 (_tmp2_, "") != 0;
		_g_free0 (_tmp2_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		ObjectsProject* _tmp29_;
		{
			GeeArrayList* _project_list = NULL;
			ServicesStore* _tmp3_;
			GeeArrayList* _tmp4_;
			GeeArrayList* _tmp5_;
			gint _project_size = 0;
			GeeArrayList* _tmp6_;
			gint _tmp7_;
			gint _tmp8_;
			gint _project_index = 0;
			_tmp3_ = services_store_instance ();
			_tmp4_ = services_store_get_projects (_tmp3_);
			_tmp5_ = _tmp4_;
			_project_list = _tmp5_;
			_tmp6_ = _project_list;
			_tmp7_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp6_);
			_tmp8_ = _tmp7_;
			_project_size = _tmp8_;
			_project_index = -1;
			while (TRUE) {
				gint _tmp9_;
				gint _tmp10_;
				ObjectsProject* project = NULL;
				GeeArrayList* _tmp11_;
				gpointer _tmp12_;
				gboolean _tmp13_ = FALSE;
				gboolean _tmp14_ = FALSE;
				ObjectsProject* _tmp15_;
				const gchar* _tmp16_;
				const gchar* _tmp17_;
				gchar* _tmp18_;
				gchar* _tmp19_;
				gboolean _tmp20_;
				_project_index = _project_index + 1;
				_tmp9_ = _project_index;
				_tmp10_ = _project_size;
				if (!(_tmp9_ < _tmp10_)) {
					break;
				}
				_tmp11_ = _project_list;
				_tmp12_ = gee_abstract_list_get ((GeeAbstractList*) _tmp11_, _project_index);
				project = (ObjectsProject*) _tmp12_;
				_tmp15_ = project;
				_tmp16_ = objects_base_object_get_id ((ObjectsBaseObject*) _tmp15_);
				_tmp17_ = _tmp16_;
				_tmp18_ = string_strip (project_id);
				_tmp19_ = _tmp18_;
				_tmp20_ = g_strcmp0 (_tmp17_, _tmp19_) == 0;
				_g_free0 (_tmp19_);
				if (_tmp20_) {
					ObjectsProject* _tmp21_;
					gboolean _tmp22_;
					gboolean _tmp23_;
					_tmp21_ = project;
					_tmp22_ = objects_project_get_is_archived (_tmp21_);
					_tmp23_ = _tmp22_;
					_tmp14_ = !_tmp23_;
				} else {
					_tmp14_ = FALSE;
				}
				if (_tmp14_) {
					ObjectsProject* _tmp24_;
					gboolean _tmp25_;
					gboolean _tmp26_;
					_tmp24_ = project;
					_tmp25_ = objects_project_get_is_deleted (_tmp24_);
					_tmp26_ = _tmp25_;
					_tmp13_ = !_tmp26_;
				} else {
					_tmp13_ = FALSE;
				}
				if (_tmp13_) {
					ObjectsProject* _tmp27_;
					ObjectsProject* _tmp28_;
					_tmp27_ = project;
					_tmp28_ = _g_object_ref0 (_tmp27_);
					_g_object_unref0 (target_project);
					target_project = _tmp28_;
					_g_object_unref0 (project);
					break;
				}
				_g_object_unref0 (project);
			}
		}
		_tmp29_ = target_project;
		if (_tmp29_ == NULL) {
			gchar* _tmp30_;
			_tmp30_ = g_strdup_printf ("Error: Project ID '%s' not found", project_id);
			_g_free0 (_vala_error_message);
			_vala_error_message = _tmp30_;
			result = NULL;
			_g_object_unref0 (target_project);
			if (error_message) {
				*error_message = _vala_error_message;
			} else {
				_g_free0 (_vala_error_message);
			}
			return result;
		}
	} else {
		gboolean _tmp31_ = FALSE;
		if (project_name != NULL) {
			gchar* _tmp32_;
			gchar* _tmp33_;
			_tmp32_ = string_strip (project_name);
			_tmp33_ = _tmp32_;
			_tmp31_ = g_strcmp0 (_tmp33_, "") != 0;
			_g_free0 (_tmp33_);
		} else {
			_tmp31_ = FALSE;
		}
		if (_tmp31_) {
			gchar* search_name = NULL;
			gchar* _tmp34_;
			gchar* _tmp35_;
			gchar* _tmp36_;
			gchar* _tmp37_;
			ObjectsProject* _tmp65_;
			_tmp34_ = string_strip (project_name);
			_tmp35_ = _tmp34_;
			_tmp36_ = g_utf8_strdown (_tmp35_, (gssize) -1);
			_tmp37_ = _tmp36_;
			_g_free0 (_tmp35_);
			search_name = _tmp37_;
			{
				GeeArrayList* _project_list = NULL;
				ServicesStore* _tmp38_;
				GeeArrayList* _tmp39_;
				GeeArrayList* _tmp40_;
				gint _project_size = 0;
				GeeArrayList* _tmp41_;
				gint _tmp42_;
				gint _tmp43_;
				gint _project_index = 0;
				_tmp38_ = services_store_instance ();
				_tmp39_ = services_store_get_projects (_tmp38_);
				_tmp40_ = _tmp39_;
				_project_list = _tmp40_;
				_tmp41_ = _project_list;
				_tmp42_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp41_);
				_tmp43_ = _tmp42_;
				_project_size = _tmp43_;
				_project_index = -1;
				while (TRUE) {
					gint _tmp44_;
					gint _tmp45_;
					ObjectsProject* project = NULL;
					GeeArrayList* _tmp46_;
					gpointer _tmp47_;
					gboolean _tmp48_ = FALSE;
					gboolean _tmp49_ = FALSE;
					ObjectsProject* _tmp50_;
					const gchar* _tmp51_;
					const gchar* _tmp52_;
					gchar* _tmp53_;
					gchar* _tmp54_;
					const gchar* _tmp55_;
					gboolean _tmp56_;
					_project_index = _project_index + 1;
					_tmp44_ = _project_index;
					_tmp45_ = _project_size;
					if (!(_tmp44_ < _tmp45_)) {
						break;
					}
					_tmp46_ = _project_list;
					_tmp47_ = gee_abstract_list_get ((GeeAbstractList*) _tmp46_, _project_index);
					project = (ObjectsProject*) _tmp47_;
					_tmp50_ = project;
					_tmp51_ = objects_base_object_get_name ((ObjectsBaseObject*) _tmp50_);
					_tmp52_ = _tmp51_;
					_tmp53_ = g_utf8_strdown (_tmp52_, (gssize) -1);
					_tmp54_ = _tmp53_;
					_tmp55_ = search_name;
					_tmp56_ = g_strcmp0 (_tmp54_, _tmp55_) == 0;
					_g_free0 (_tmp54_);
					if (_tmp56_) {
						ObjectsProject* _tmp57_;
						gboolean _tmp58_;
						gboolean _tmp59_;
						_tmp57_ = project;
						_tmp58_ = objects_project_get_is_archived (_tmp57_);
						_tmp59_ = _tmp58_;
						_tmp49_ = !_tmp59_;
					} else {
						_tmp49_ = FALSE;
					}
					if (_tmp49_) {
						ObjectsProject* _tmp60_;
						gboolean _tmp61_;
						gboolean _tmp62_;
						_tmp60_ = project;
						_tmp61_ = objects_project_get_is_deleted (_tmp60_);
						_tmp62_ = _tmp61_;
						_tmp48_ = !_tmp62_;
					} else {
						_tmp48_ = FALSE;
					}
					if (_tmp48_) {
						ObjectsProject* _tmp63_;
						ObjectsProject* _tmp64_;
						_tmp63_ = project;
						_tmp64_ = _g_object_ref0 (_tmp63_);
						_g_object_unref0 (target_project);
						target_project = _tmp64_;
						_g_object_unref0 (project);
						break;
					}
					_g_object_unref0 (project);
				}
			}
			_tmp65_ = target_project;
			if (_tmp65_ == NULL) {
				gchar* _tmp66_;
				_tmp66_ = g_strdup_printf ("Error: Project '%s' not found", project_name);
				_g_free0 (_vala_error_message);
				_vala_error_message = _tmp66_;
				result = NULL;
				_g_free0 (search_name);
				_g_object_unref0 (target_project);
				if (error_message) {
					*error_message = _vala_error_message;
				} else {
					_g_free0 (_vala_error_message);
				}
				return result;
			}
			_g_free0 (search_name);
		} else {
			ServicesStore* _tmp67_;
			ObjectsProject* _tmp68_;
			ObjectsProject* _tmp69_;
			_tmp67_ = services_store_instance ();
			_tmp68_ = services_store_get_inbox_project (_tmp67_);
			_g_object_unref0 (target_project);
			target_project = _tmp68_;
			_tmp69_ = target_project;
			if (_tmp69_ == NULL) {
				gchar* _tmp70_;
				_tmp70_ = g_strdup ("Error: No inbox project found");
				_g_free0 (_vala_error_message);
				_vala_error_message = _tmp70_;
				result = NULL;
				_g_object_unref0 (target_project);
				if (error_message) {
					*error_message = _vala_error_message;
				} else {
					_g_free0 (_vala_error_message);
				}
				return result;
			}
		}
	}
	result = target_project;
	if (error_message) {
		*error_message = _vala_error_message;
	} else {
		_g_free0 (_vala_error_message);
	}
	return result;
}

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;
}

ObjectsItem*
planify_cli_task_creator_create_item (const gchar* content,
                                      const gchar* description,
                                      gint priority,
                                      GDateTime* due_datetime,
                                      ObjectsProject* project,
                                      const gchar* parent_id)
{
	ObjectsItem* item = NULL;
	ObjectsItem* _tmp0_;
	ObjectsItem* _tmp1_;
	Util* _tmp2_;
	Util* _tmp3_;
	ObjectsItem* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	ObjectsItem* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	ObjectsItem* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	ObjectsItem* _tmp13_;
	ObjectsItem* _tmp14_;
	GDateTime* _tmp15_;
	GDateTime* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gboolean _tmp19_ = FALSE;
	gboolean _tmp25_ = FALSE;
	ObjectsItem* result;
	g_return_val_if_fail (content != NULL, NULL);
	g_return_val_if_fail (project != NULL, NULL);
	_tmp0_ = objects_item_new ();
	item = _tmp0_;
	_tmp1_ = item;
	_tmp2_ = util_get_default ();
	_tmp3_ = _tmp2_;
	_tmp4_ = item;
	_tmp5_ = util_generate_id (_tmp3_, (ObjectsBaseObject*) _tmp4_);
	_tmp6_ = _tmp5_;
	objects_base_object_set_id ((ObjectsBaseObject*) _tmp1_, _tmp6_);
	_g_free0 (_tmp6_);
	_g_object_unref0 (_tmp3_);
	_tmp7_ = item;
	_tmp8_ = string_strip (content);
	_tmp9_ = _tmp8_;
	objects_item_set_content (_tmp7_, _tmp9_);
	_g_free0 (_tmp9_);
	_tmp10_ = item;
	_tmp11_ = objects_base_object_get_id ((ObjectsBaseObject*) project);
	_tmp12_ = _tmp11_;
	objects_item_set_project_id (_tmp10_, _tmp12_);
	_tmp13_ = item;
	objects_item_set_priority (_tmp13_, 5 - priority);
	_tmp14_ = item;
	_tmp15_ = g_date_time_new_now_local ();
	_tmp16_ = _tmp15_;
	_tmp17_ = g_date_time_to_string (_tmp16_);
	_tmp18_ = _tmp17_;
	objects_item_set_added_at (_tmp14_, _tmp18_);
	_g_free0 (_tmp18_);
	_g_date_time_unref0 (_tmp16_);
	if (parent_id != NULL) {
		gchar* _tmp20_;
		gchar* _tmp21_;
		_tmp20_ = string_strip (parent_id);
		_tmp21_ = _tmp20_;
		_tmp19_ = g_strcmp0 (_tmp21_, "") != 0;
		_g_free0 (_tmp21_);
	} else {
		_tmp19_ = FALSE;
	}
	if (_tmp19_) {
		ObjectsItem* _tmp22_;
		gchar* _tmp23_;
		gchar* _tmp24_;
		_tmp22_ = item;
		_tmp23_ = string_strip (parent_id);
		_tmp24_ = _tmp23_;
		objects_item_set_parent_id (_tmp22_, _tmp24_);
		_g_free0 (_tmp24_);
	}
	if (description != NULL) {
		gchar* _tmp26_;
		gchar* _tmp27_;
		_tmp26_ = string_strip (description);
		_tmp27_ = _tmp26_;
		_tmp25_ = g_strcmp0 (_tmp27_, "") != 0;
		_g_free0 (_tmp27_);
	} else {
		_tmp25_ = FALSE;
	}
	if (_tmp25_) {
		ObjectsItem* _tmp28_;
		gchar* _tmp29_;
		gchar* _tmp30_;
		_tmp28_ = item;
		_tmp29_ = string_strip (description);
		_tmp30_ = _tmp29_;
		objects_item_set_description (_tmp28_, _tmp30_);
		_g_free0 (_tmp30_);
	}
	if (due_datetime != NULL) {
		ObjectsItem* _tmp31_;
		ObjectsDueDate* _tmp32_;
		ObjectsDueDate* _tmp33_;
		gchar* _tmp34_;
		gchar* _tmp35_;
		_tmp31_ = item;
		_tmp32_ = objects_item_get_due (_tmp31_);
		_tmp33_ = _tmp32_;
		_tmp34_ = utils_datetime_get_todoist_datetime_format (due_datetime);
		_tmp35_ = _tmp34_;
		objects_due_date_set_date (_tmp33_, _tmp35_);
		_g_free0 (_tmp35_);
	}
	result = item;
	return result;
}

static gpointer
_g_main_context_ref0 (gpointer self)
{
	return self ? g_main_context_ref (self) : NULL;
}

gboolean
planify_cli_task_creator_save_and_notify (ObjectsItem* item)
{
	ServicesStore* _tmp0_;
	gboolean dbus_notified = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (item != NULL, FALSE);
	_tmp0_ = services_store_instance ();
	services_store_insert_item (_tmp0_, item, TRUE, TRUE);
	dbus_notified = FALSE;
	{
		DBusClient* _tmp1_;
		DBusClientInterface* _tmp2_;
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		_tmp1_ = dbus_client_get_default ();
		_tmp2_ = _tmp1_->interface;
		_tmp3_ = objects_base_object_get_id ((ObjectsBaseObject*) item);
		_tmp4_ = _tmp3_;
		dbus_client_interface_add_item (_tmp2_, _tmp4_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		dbus_notified = TRUE;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp5_;
		const gchar* _tmp6_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		g_debug ("TaskCreator.vala:148: DBus notification failed: %s", _tmp6_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp7_ = FALSE;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp7_;
	}
	if (dbus_notified) {
		GMainContext* main_context = NULL;
		GMainContext* _tmp8_;
		GMainContext* _tmp9_;
		_tmp8_ = g_main_context_default ();
		_tmp9_ = _g_main_context_ref0 (_tmp8_);
		main_context = _tmp9_;
		while (TRUE) {
			GMainContext* _tmp10_;
			GMainContext* _tmp11_;
			_tmp10_ = main_context;
			if (!g_main_context_pending (_tmp10_)) {
				break;
			}
			_tmp11_ = main_context;
			g_main_context_iteration (_tmp11_, FALSE);
		}
		_g_main_context_unref0 (main_context);
	}
	result = TRUE;
	return result;
}

PlanifyCLITaskCreator*
planify_cli_task_creator_construct (GType object_type)
{
	PlanifyCLITaskCreator * self = NULL;
	self = (PlanifyCLITaskCreator*) g_object_new (object_type, NULL);
	return self;
}

PlanifyCLITaskCreator*
planify_cli_task_creator_new (void)
{
	return planify_cli_task_creator_construct (PLANIFY_CLI_TYPE_TASK_CREATOR);
}

static void
planify_cli_task_creator_class_init (PlanifyCLITaskCreatorClass * klass,
                                     gpointer klass_data)
{
	planify_cli_task_creator_parent_class = g_type_class_peek_parent (klass);
}

static void
planify_cli_task_creator_instance_init (PlanifyCLITaskCreator * self,
                                        gpointer klass)
{
}

static GType
planify_cli_task_creator_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PlanifyCLITaskCreatorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) planify_cli_task_creator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PlanifyCLITaskCreator), 0, (GInstanceInitFunc) planify_cli_task_creator_instance_init, NULL };
	GType planify_cli_task_creator_type_id;
	planify_cli_task_creator_type_id = g_type_register_static (G_TYPE_OBJECT, "PlanifyCLITaskCreator", &g_define_type_info, 0);
	return planify_cli_task_creator_type_id;
}

GType
planify_cli_task_creator_get_type (void)
{
	static volatile gsize planify_cli_task_creator_type_id__once = 0;
	if (g_once_init_enter (&planify_cli_task_creator_type_id__once)) {
		GType planify_cli_task_creator_type_id;
		planify_cli_task_creator_type_id = planify_cli_task_creator_get_type_once ();
		g_once_init_leave (&planify_cli_task_creator_type_id__once, planify_cli_task_creator_type_id);
	}
	return planify_cli_task_creator_type_id__once;
}

