/* search-repository.c generated by valac 0.56.19, the Vala compiler
 * generated from search-repository.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
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include <glib-object.h>
#include <sqlite3.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gstdio.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_TYPE_SEARCH_REPOSITORY (planify_search_repository_get_type ())
#define PLANIFY_SEARCH_REPOSITORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLANIFY_TYPE_SEARCH_REPOSITORY, PlanifySearchRepository))
#define PLANIFY_SEARCH_REPOSITORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PLANIFY_TYPE_SEARCH_REPOSITORY, PlanifySearchRepositoryClass))
#define PLANIFY_IS_SEARCH_REPOSITORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PLANIFY_TYPE_SEARCH_REPOSITORY))
#define PLANIFY_IS_SEARCH_REPOSITORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PLANIFY_TYPE_SEARCH_REPOSITORY))
#define PLANIFY_SEARCH_REPOSITORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PLANIFY_TYPE_SEARCH_REPOSITORY, PlanifySearchRepositoryClass))

typedef struct _PlanifySearchRepository PlanifySearchRepository;
typedef struct _PlanifySearchRepositoryClass PlanifySearchRepositoryClass;
typedef struct _PlanifySearchRepositoryPrivate PlanifySearchRepositoryPrivate;
enum  {
	PLANIFY_SEARCH_REPOSITORY_0_PROPERTY,
	PLANIFY_SEARCH_REPOSITORY_NUM_PROPERTIES
};
static GParamSpec* planify_search_repository_properties[PLANIFY_SEARCH_REPOSITORY_NUM_PROPERTIES];
#define _sqlite3_close0(var) ((var == NULL) ? NULL : (var = (sqlite3_close (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))

#define PLANIFY_SEARCH_REPOSITORY_TYPE_RESULT_META (planify_search_repository_result_meta_get_type ())
typedef struct _PlanifySearchRepositoryResultMeta PlanifySearchRepositoryResultMeta;
#define _sqlite3_finalize0(var) ((var == NULL) ? NULL : (var = (sqlite3_finalize (var), NULL)))

struct _PlanifySearchRepository {
	GObject parent_instance;
	PlanifySearchRepositoryPrivate * priv;
};

struct _PlanifySearchRepositoryClass {
	GObjectClass parent_class;
};

struct _PlanifySearchRepositoryPrivate {
	sqlite3* db;
	gboolean db_open;
};

struct _PlanifySearchRepositoryResultMeta {
	gchar* name;
	gchar* description;
};

static gint PlanifySearchRepository_private_offset;
static gpointer planify_search_repository_parent_class = NULL;

VALA_EXTERN GType planify_search_repository_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PlanifySearchRepository, g_object_unref)
VALA_EXTERN gchar** planify_search_repository_search (PlanifySearchRepository* self,
                                          const gchar* query,
                                          gint* result_length1);
static void _g_free0_ (gpointer var);
static void planify_search_repository_search_projects (PlanifySearchRepository* self,
                                                const gchar* term,
                                                GPtrArray* results);
static void planify_search_repository_search_items (PlanifySearchRepository* self,
                                             const gchar* term,
                                             GPtrArray* results);
static gchar** _vala_array_dup2 (gchar** self,
                          gssize length);
VALA_EXTERN GType planify_search_repository_result_meta_get_type (void) G_GNUC_CONST ;
VALA_EXTERN PlanifySearchRepositoryResultMeta* planify_search_repository_result_meta_dup (const PlanifySearchRepositoryResultMeta* self);
VALA_EXTERN void planify_search_repository_result_meta_free (PlanifySearchRepositoryResultMeta* self);
VALA_EXTERN void planify_search_repository_result_meta_copy (const PlanifySearchRepositoryResultMeta* self,
                                                 PlanifySearchRepositoryResultMeta* dest);
VALA_EXTERN void planify_search_repository_result_meta_destroy (PlanifySearchRepositoryResultMeta* self);
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (PlanifySearchRepositoryResultMeta, planify_search_repository_result_meta_destroy)
VALA_EXTERN PlanifySearchRepositoryResultMeta* planify_search_repository_get_meta (PlanifySearchRepository* self,
                                                                       const gchar* identifier);
static PlanifySearchRepositoryResultMeta* planify_search_repository_get_project_meta (PlanifySearchRepository* self,
                                                                               const gchar* project_id);
static PlanifySearchRepositoryResultMeta* planify_search_repository_get_item_meta (PlanifySearchRepository* self,
                                                                            const gchar* item_id);
VALA_EXTERN PlanifySearchRepository* planify_search_repository_new (void);
VALA_EXTERN PlanifySearchRepository* planify_search_repository_construct (GType object_type);
static GObject * planify_search_repository_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void planify_search_repository_finalize (GObject * obj);
static GType planify_search_repository_get_type_once (void);

static inline gpointer
planify_search_repository_get_instance_private (PlanifySearchRepository* self)
{
	return G_STRUCT_MEMBER_P (self, PlanifySearchRepository_private_offset);
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static gchar**
_vala_array_dup2 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

gchar**
planify_search_repository_search (PlanifySearchRepository* self,
                                  const gchar* query,
                                  gint* result_length1)
{
	GPtrArray* results = NULL;
	GPtrArray* _tmp2_;
	gchar* term = NULL;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	const gchar* _tmp9_;
	GPtrArray* _tmp10_;
	const gchar* _tmp11_;
	GPtrArray* _tmp12_;
	GPtrArray* _tmp13_;
	gpointer* _tmp14_;
	gint _tmp14__length1;
	gchar** _tmp15_;
	gint _tmp15__length1;
	gchar** _tmp16_;
	gint _tmp16__length1;
	gchar** result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (query != NULL, NULL);
	if (!self->priv->db_open) {
		gchar** _tmp0_;
		gchar** _tmp1_;
		gint _tmp1__length1;
		_tmp0_ = g_new0 (gchar*, 0 + 1);
		_tmp1_ = _tmp0_;
		_tmp1__length1 = 0;
		if (result_length1) {
			*result_length1 = _tmp1__length1;
		}
		result = _tmp1_;
		return result;
	}
	_tmp2_ = g_ptr_array_new_full ((guint) 0, _g_free0_);
	results = _tmp2_;
	_tmp3_ = g_utf8_strdown (query, (gssize) -1);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strconcat ("%", _tmp4_, NULL);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_strconcat (_tmp6_, "%", NULL);
	_tmp8_ = _tmp7_;
	_g_free0 (_tmp6_);
	_g_free0 (_tmp4_);
	term = _tmp8_;
	_tmp9_ = term;
	_tmp10_ = results;
	planify_search_repository_search_projects (self, _tmp9_, _tmp10_);
	_tmp11_ = term;
	_tmp12_ = results;
	planify_search_repository_search_items (self, _tmp11_, _tmp12_);
	_tmp13_ = results;
	_tmp14_ = _tmp13_->pdata;
	_tmp14__length1 = _tmp13_->len;
	_tmp15_ = (_tmp14_ != NULL) ? _vala_array_dup2 (_tmp14_, _tmp14__length1) : _tmp14_;
	_tmp15__length1 = _tmp14__length1;
	_tmp16_ = _tmp15_;
	_tmp16__length1 = _tmp15__length1;
	if (result_length1) {
		*result_length1 = _tmp16__length1;
	}
	result = _tmp16_;
	_g_free0 (term);
	_g_ptr_array_unref0 (results);
	return result;
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

PlanifySearchRepositoryResultMeta*
planify_search_repository_get_meta (PlanifySearchRepository* self,
                                    const gchar* identifier)
{
	PlanifySearchRepositoryResultMeta* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (identifier != NULL, NULL);
	if (!self->priv->db_open) {
		result = NULL;
		return result;
	}
	if (g_str_has_prefix (identifier, "project-")) {
		gchar* _tmp0_;
		gchar* _tmp1_;
		PlanifySearchRepositoryResultMeta* _tmp2_;
		PlanifySearchRepositoryResultMeta* _tmp3_;
		_tmp0_ = string_substring (identifier, (glong) 8, (glong) -1);
		_tmp1_ = _tmp0_;
		_tmp2_ = planify_search_repository_get_project_meta (self, _tmp1_);
		_tmp3_ = _tmp2_;
		_g_free0 (_tmp1_);
		result = _tmp3_;
		return result;
	} else {
		if (g_str_has_prefix (identifier, "item-")) {
			gchar* _tmp4_;
			gchar* _tmp5_;
			PlanifySearchRepositoryResultMeta* _tmp6_;
			PlanifySearchRepositoryResultMeta* _tmp7_;
			_tmp4_ = string_substring (identifier, (glong) 5, (glong) -1);
			_tmp5_ = _tmp4_;
			_tmp6_ = planify_search_repository_get_item_meta (self, _tmp5_);
			_tmp7_ = _tmp6_;
			_g_free0 (_tmp5_);
			result = _tmp7_;
			return result;
		}
	}
	result = NULL;
	return result;
}

static void
planify_search_repository_search_projects (PlanifySearchRepository* self,
                                           const gchar* term,
                                           GPtrArray* results)
{
	sqlite3_stmt* stmt = NULL;
	gchar* sql = NULL;
	gchar* _tmp0_;
	sqlite3* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	sqlite3_stmt* _tmp6_ = NULL;
	gint _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (term != NULL);
	g_return_if_fail (results != NULL);
	_tmp0_ = g_strdup ("\n" \
"            SELECT id FROM Projects\n" \
"            WHERE is_deleted = 0 AND is_archived = 0\n" \
"            AND LOWER(name) LIKE $term\n" \
"            LIMIT 5;\n" \
"        ");
	sql = _tmp0_;
	_tmp1_ = self->priv->db;
	_tmp2_ = sql;
	_tmp3_ = sql;
	_tmp4_ = strlen (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp7_ = sqlite3_prepare_v2 (_tmp1_, _tmp2_, _tmp5_, &_tmp6_, NULL);
	_sqlite3_finalize0 (stmt);
	stmt = _tmp6_;
	if (_tmp7_ == SQLITE_OK) {
		sqlite3_stmt* _tmp8_;
		sqlite3_stmt* _tmp9_;
		gchar* _tmp10_;
		GDestroyNotify _tmp11_;
		_tmp8_ = stmt;
		_tmp9_ = stmt;
		_tmp10_ = g_strdup (term);
		_tmp11_ = g_free;
		sqlite3_bind_text (_tmp8_, sqlite3_bind_parameter_index (_tmp9_, "$term"), _tmp10_, -1, _tmp11_);
		while (TRUE) {
			sqlite3_stmt* _tmp12_;
			sqlite3_stmt* _tmp13_;
			const gchar* _tmp14_;
			gchar* _tmp15_;
			_tmp12_ = stmt;
			if (!(sqlite3_step (_tmp12_) == SQLITE_ROW)) {
				break;
			}
			_tmp13_ = stmt;
			_tmp14_ = (const gchar*) sqlite3_column_text (_tmp13_, 0);
			_tmp15_ = g_strconcat ("project-", _tmp14_, NULL);
			g_ptr_array_add (results, _tmp15_);
		}
	}
	_g_free0 (sql);
	_sqlite3_finalize0 (stmt);
}

static void
planify_search_repository_search_items (PlanifySearchRepository* self,
                                        const gchar* term,
                                        GPtrArray* results)
{
	sqlite3_stmt* stmt = NULL;
	gchar* sql = NULL;
	gchar* _tmp0_;
	sqlite3* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	sqlite3_stmt* _tmp6_ = NULL;
	gint _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (term != NULL);
	g_return_if_fail (results != NULL);
	_tmp0_ = g_strdup ("\n" \
"            SELECT i.id FROM Items i\n" \
"            LEFT JOIN Projects p ON i.project_id = p.id\n" \
"            WHERE i.is_deleted = 0 AND i.checked = 0\n" \
"            AND (p.is_archived = 0 OR p.is_archived IS NULL)\n" \
"            AND (LOWER(i.content) LIKE $term OR LOWER(i.description) L" \
"IKE $term)\n" \
"            LIMIT 5;\n" \
"        ");
	sql = _tmp0_;
	_tmp1_ = self->priv->db;
	_tmp2_ = sql;
	_tmp3_ = sql;
	_tmp4_ = strlen (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp7_ = sqlite3_prepare_v2 (_tmp1_, _tmp2_, _tmp5_, &_tmp6_, NULL);
	_sqlite3_finalize0 (stmt);
	stmt = _tmp6_;
	if (_tmp7_ == SQLITE_OK) {
		sqlite3_stmt* _tmp8_;
		sqlite3_stmt* _tmp9_;
		gchar* _tmp10_;
		GDestroyNotify _tmp11_;
		_tmp8_ = stmt;
		_tmp9_ = stmt;
		_tmp10_ = g_strdup (term);
		_tmp11_ = g_free;
		sqlite3_bind_text (_tmp8_, sqlite3_bind_parameter_index (_tmp9_, "$term"), _tmp10_, -1, _tmp11_);
		while (TRUE) {
			sqlite3_stmt* _tmp12_;
			sqlite3_stmt* _tmp13_;
			const gchar* _tmp14_;
			gchar* _tmp15_;
			_tmp12_ = stmt;
			if (!(sqlite3_step (_tmp12_) == SQLITE_ROW)) {
				break;
			}
			_tmp13_ = stmt;
			_tmp14_ = (const gchar*) sqlite3_column_text (_tmp13_, 0);
			_tmp15_ = g_strconcat ("item-", _tmp14_, NULL);
			g_ptr_array_add (results, _tmp15_);
		}
	}
	_g_free0 (sql);
	_sqlite3_finalize0 (stmt);
}

static gpointer
_planify_search_repository_result_meta_dup0 (gpointer self)
{
	return self ? planify_search_repository_result_meta_dup (self) : NULL;
}

static PlanifySearchRepositoryResultMeta*
planify_search_repository_get_project_meta (PlanifySearchRepository* self,
                                            const gchar* project_id)
{
	sqlite3_stmt* stmt = NULL;
	gchar* sql = NULL;
	gchar* _tmp0_;
	sqlite3* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	sqlite3_stmt* _tmp6_ = NULL;
	gint _tmp7_;
	PlanifySearchRepositoryResultMeta* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (project_id != NULL, NULL);
	_tmp0_ = g_strdup ("\n" \
"            SELECT p.name,\n" \
"                (SELECT COUNT(*) FROM Items i\n" \
"                 WHERE i.project_id = p.id AND i.checked = 0 AND i.is_" \
"deleted = 0)\n" \
"            FROM Projects p WHERE p.id = $id;\n" \
"        ");
	sql = _tmp0_;
	_tmp1_ = self->priv->db;
	_tmp2_ = sql;
	_tmp3_ = sql;
	_tmp4_ = strlen (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp7_ = sqlite3_prepare_v2 (_tmp1_, _tmp2_, _tmp5_, &_tmp6_, NULL);
	_sqlite3_finalize0 (stmt);
	stmt = _tmp6_;
	if (_tmp7_ == SQLITE_OK) {
		sqlite3_stmt* _tmp8_;
		sqlite3_stmt* _tmp9_;
		gchar* _tmp10_;
		GDestroyNotify _tmp11_;
		sqlite3_stmt* _tmp12_;
		_tmp8_ = stmt;
		_tmp9_ = stmt;
		_tmp10_ = g_strdup (project_id);
		_tmp11_ = g_free;
		sqlite3_bind_text (_tmp8_, sqlite3_bind_parameter_index (_tmp9_, "$id"), _tmp10_, -1, _tmp11_);
		_tmp12_ = stmt;
		if (sqlite3_step (_tmp12_) == SQLITE_ROW) {
			gint count = 0;
			sqlite3_stmt* _tmp13_;
			const gchar* _tmp14_ = NULL;
			sqlite3_stmt* _tmp15_;
			const gchar* _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			PlanifySearchRepositoryResultMeta _tmp19_ = {0};
			PlanifySearchRepositoryResultMeta _tmp20_;
			PlanifySearchRepositoryResultMeta* _tmp21_;
			PlanifySearchRepositoryResultMeta* _tmp22_;
			_tmp13_ = stmt;
			count = sqlite3_column_int (_tmp13_, 1);
			if (count == 1) {
				_tmp14_ = "task";
			} else {
				_tmp14_ = "tasks";
			}
			_tmp15_ = stmt;
			_tmp16_ = (const gchar*) sqlite3_column_text (_tmp15_, 0);
			_tmp17_ = g_strdup (_tmp16_);
			_tmp18_ = g_strdup_printf ("%d %s", count, _tmp14_);
			memset (&_tmp19_, 0, sizeof (PlanifySearchRepositoryResultMeta));
			_g_free0 (_tmp19_.name);
			_tmp19_.name = _tmp17_;
			_g_free0 (_tmp19_.description);
			_tmp19_.description = _tmp18_;
			_tmp20_ = _tmp19_;
			_tmp21_ = _planify_search_repository_result_meta_dup0 (&_tmp20_);
			_tmp22_ = _tmp21_;
			planify_search_repository_result_meta_destroy (&_tmp20_);
			result = _tmp22_;
			_g_free0 (sql);
			_sqlite3_finalize0 (stmt);
			return result;
		}
	}
	result = NULL;
	_g_free0 (sql);
	_sqlite3_finalize0 (stmt);
	return result;
}

static PlanifySearchRepositoryResultMeta*
planify_search_repository_get_item_meta (PlanifySearchRepository* self,
                                         const gchar* item_id)
{
	sqlite3_stmt* stmt = NULL;
	gchar* sql = NULL;
	gchar* _tmp0_;
	sqlite3* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	sqlite3_stmt* _tmp6_ = NULL;
	gint _tmp7_;
	PlanifySearchRepositoryResultMeta* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (item_id != NULL, NULL);
	_tmp0_ = g_strdup ("\n" \
"            SELECT i.content, p.name FROM Items i\n" \
"            LEFT JOIN Projects p ON i.project_id = p.id\n" \
"            WHERE i.id = $id;\n" \
"        ");
	sql = _tmp0_;
	_tmp1_ = self->priv->db;
	_tmp2_ = sql;
	_tmp3_ = sql;
	_tmp4_ = strlen (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp7_ = sqlite3_prepare_v2 (_tmp1_, _tmp2_, _tmp5_, &_tmp6_, NULL);
	_sqlite3_finalize0 (stmt);
	stmt = _tmp6_;
	if (_tmp7_ == SQLITE_OK) {
		sqlite3_stmt* _tmp8_;
		sqlite3_stmt* _tmp9_;
		gchar* _tmp10_;
		GDestroyNotify _tmp11_;
		sqlite3_stmt* _tmp12_;
		_tmp8_ = stmt;
		_tmp9_ = stmt;
		_tmp10_ = g_strdup (item_id);
		_tmp11_ = g_free;
		sqlite3_bind_text (_tmp8_, sqlite3_bind_parameter_index (_tmp9_, "$id"), _tmp10_, -1, _tmp11_);
		_tmp12_ = stmt;
		if (sqlite3_step (_tmp12_) == SQLITE_ROW) {
			const gchar* _tmp13_ = NULL;
			sqlite3_stmt* _tmp14_;
			const gchar* _tmp15_;
			sqlite3_stmt* _tmp16_;
			const gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			PlanifySearchRepositoryResultMeta _tmp20_ = {0};
			PlanifySearchRepositoryResultMeta _tmp21_;
			PlanifySearchRepositoryResultMeta* _tmp22_;
			PlanifySearchRepositoryResultMeta* _tmp23_;
			_tmp14_ = stmt;
			_tmp15_ = (const gchar*) sqlite3_column_text (_tmp14_, 1);
			_tmp13_ = _tmp15_;
			if (_tmp13_ == NULL) {
				_tmp13_ = "";
			}
			_tmp16_ = stmt;
			_tmp17_ = (const gchar*) sqlite3_column_text (_tmp16_, 0);
			_tmp18_ = g_strdup (_tmp17_);
			_tmp19_ = g_strdup (_tmp13_);
			memset (&_tmp20_, 0, sizeof (PlanifySearchRepositoryResultMeta));
			_g_free0 (_tmp20_.name);
			_tmp20_.name = _tmp18_;
			_g_free0 (_tmp20_.description);
			_tmp20_.description = _tmp19_;
			_tmp21_ = _tmp20_;
			_tmp22_ = _planify_search_repository_result_meta_dup0 (&_tmp21_);
			_tmp23_ = _tmp22_;
			planify_search_repository_result_meta_destroy (&_tmp21_);
			result = _tmp23_;
			_g_free0 (sql);
			_sqlite3_finalize0 (stmt);
			return result;
		}
	}
	result = NULL;
	_g_free0 (sql);
	_sqlite3_finalize0 (stmt);
	return result;
}

PlanifySearchRepository*
planify_search_repository_construct (GType object_type)
{
	PlanifySearchRepository * self = NULL;
	self = (PlanifySearchRepository*) g_object_new (object_type, NULL);
	return self;
}

PlanifySearchRepository*
planify_search_repository_new (void)
{
	return planify_search_repository_construct (PLANIFY_TYPE_SEARCH_REPOSITORY);
}

void
planify_search_repository_result_meta_copy (const PlanifySearchRepositoryResultMeta* self,
                                            PlanifySearchRepositoryResultMeta* dest)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	_tmp0_ = (*self).name;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 ((*dest).name);
	(*dest).name = _tmp1_;
	_tmp2_ = (*self).description;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 ((*dest).description);
	(*dest).description = _tmp3_;
}

void
planify_search_repository_result_meta_destroy (PlanifySearchRepositoryResultMeta* self)
{
	_g_free0 ((*self).name);
	_g_free0 ((*self).description);
}

PlanifySearchRepositoryResultMeta*
planify_search_repository_result_meta_dup (const PlanifySearchRepositoryResultMeta* self)
{
	PlanifySearchRepositoryResultMeta* dup;
	dup = g_new0 (PlanifySearchRepositoryResultMeta, 1);
	planify_search_repository_result_meta_copy (self, dup);
	return dup;
}

void
planify_search_repository_result_meta_free (PlanifySearchRepositoryResultMeta* self)
{
	planify_search_repository_result_meta_destroy (self);
	g_free (self);
}

static GType
planify_search_repository_result_meta_get_type_once (void)
{
	GType planify_search_repository_result_meta_type_id;
	planify_search_repository_result_meta_type_id = g_boxed_type_register_static ("PlanifySearchRepositoryResultMeta", (GBoxedCopyFunc) planify_search_repository_result_meta_dup, (GBoxedFreeFunc) planify_search_repository_result_meta_free);
	return planify_search_repository_result_meta_type_id;
}

GType
planify_search_repository_result_meta_get_type (void)
{
	static volatile gsize planify_search_repository_result_meta_type_id__once = 0;
	if (g_once_init_enter (&planify_search_repository_result_meta_type_id__once)) {
		GType planify_search_repository_result_meta_type_id;
		planify_search_repository_result_meta_type_id = planify_search_repository_result_meta_get_type_once ();
		g_once_init_leave (&planify_search_repository_result_meta_type_id__once, planify_search_repository_result_meta_type_id);
	}
	return planify_search_repository_result_meta_type_id__once;
}

static GObject *
planify_search_repository_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	PlanifySearchRepository * self;
	gchar* db_path = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	parent_class = G_OBJECT_CLASS (planify_search_repository_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PLANIFY_TYPE_SEARCH_REPOSITORY, PlanifySearchRepository);
	_tmp0_ = g_get_user_data_dir ();
	_tmp1_ = g_build_filename (_tmp0_, "io.github.alainm23.planify", "database.db", NULL);
	db_path = _tmp1_;
	_tmp2_ = db_path;
	if (g_file_test (_tmp2_, G_FILE_TEST_EXISTS)) {
		const gchar* _tmp3_;
		sqlite3* _tmp4_ = NULL;
		gint _tmp5_;
		_tmp3_ = db_path;
		_tmp5_ = sqlite3_open_v2 (_tmp3_, &_tmp4_, SQLITE_OPEN_READONLY, NULL);
		_sqlite3_close0 (self->priv->db);
		self->priv->db = _tmp4_;
		if (_tmp5_ == SQLITE_OK) {
			self->priv->db_open = TRUE;
		}
	}
	if (!self->priv->db_open) {
		const gchar* _tmp6_;
		_tmp6_ = db_path;
		g_warning ("search-repository.vala:44: Could not open database: %s", _tmp6_);
	}
	_g_free0 (db_path);
	return obj;
}

static void
planify_search_repository_class_init (PlanifySearchRepositoryClass * klass,
                                      gpointer klass_data)
{
	planify_search_repository_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PlanifySearchRepository_private_offset);
	G_OBJECT_CLASS (klass)->constructor = planify_search_repository_constructor;
	G_OBJECT_CLASS (klass)->finalize = planify_search_repository_finalize;
}

static void
planify_search_repository_instance_init (PlanifySearchRepository * self,
                                         gpointer klass)
{
	self->priv = planify_search_repository_get_instance_private (self);
	self->priv->db_open = FALSE;
}

static void
planify_search_repository_finalize (GObject * obj)
{
	PlanifySearchRepository * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PLANIFY_TYPE_SEARCH_REPOSITORY, PlanifySearchRepository);
	_sqlite3_close0 (self->priv->db);
	G_OBJECT_CLASS (planify_search_repository_parent_class)->finalize (obj);
}

static GType
planify_search_repository_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PlanifySearchRepositoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) planify_search_repository_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PlanifySearchRepository), 0, (GInstanceInitFunc) planify_search_repository_instance_init, NULL };
	GType planify_search_repository_type_id;
	planify_search_repository_type_id = g_type_register_static (G_TYPE_OBJECT, "PlanifySearchRepository", &g_define_type_info, 0);
	PlanifySearchRepository_private_offset = g_type_add_instance_private (planify_search_repository_type_id, sizeof (PlanifySearchRepositoryPrivate));
	return planify_search_repository_type_id;
}

GType
planify_search_repository_get_type (void)
{
	static volatile gsize planify_search_repository_type_id__once = 0;
	if (g_once_init_enter (&planify_search_repository_type_id__once)) {
		GType planify_search_repository_type_id;
		planify_search_repository_type_id = planify_search_repository_get_type_once ();
		g_once_init_leave (&planify_search_repository_type_id__once, planify_search_repository_type_id);
	}
	return planify_search_repository_type_id__once;
}

