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

#include <glib-object.h>
#include <json-glib/json-glib.h>
#include <glib.h>
#include <string.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 DC_TYPE_MESSAGE_HISTORY (dc_message_history_get_type ())
#define DC_MESSAGE_HISTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_MESSAGE_HISTORY, DcMessageHistory))
#define DC_MESSAGE_HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_MESSAGE_HISTORY, DcMessageHistoryClass))
#define DC_IS_MESSAGE_HISTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_MESSAGE_HISTORY))
#define DC_IS_MESSAGE_HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_MESSAGE_HISTORY))
#define DC_MESSAGE_HISTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_MESSAGE_HISTORY, DcMessageHistoryClass))

typedef struct _DcMessageHistory DcMessageHistory;
typedef struct _DcMessageHistoryClass DcMessageHistoryClass;
typedef struct _DcMessageHistoryPrivate DcMessageHistoryPrivate;
enum  {
	DC_MESSAGE_HISTORY_0_PROPERTY,
	DC_MESSAGE_HISTORY_NUM_PROPERTIES
};
static GParamSpec* dc_message_history_properties[DC_MESSAGE_HISTORY_NUM_PROPERTIES];

struct _DcMessageHistory {
	GObject parent_instance;
	DcMessageHistoryPrivate * priv;
};

struct _DcMessageHistoryClass {
	GObjectClass parent_class;
};

static gpointer dc_message_history_parent_class = NULL;

VALA_EXTERN GType dc_message_history_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcMessageHistory, g_object_unref)
VALA_EXTERN gint dc_message_history_find_id (JsonArray* ids,
                                 gint message_id);
VALA_EXTERN guint dc_message_history_earlier_batch_start (guint loaded_start,
                                              guint target_index,
                                              guint batch_size);
VALA_EXTERN DcMessageHistory* dc_message_history_new (void);
VALA_EXTERN DcMessageHistory* dc_message_history_construct (GType object_type);
static GType dc_message_history_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

gint
dc_message_history_find_id (JsonArray* ids,
                            gint message_id)
{
	gint result;
	g_return_val_if_fail (ids != NULL, -1);
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				if (!_tmp0_) {
					guint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(i < json_array_get_length (ids))) {
					break;
				}
				if (((gint) json_array_get_int_element (ids, i)) == message_id) {
					result = (gint) i;
					return result;
				}
			}
		}
	}
	result = -1;
	return result;
}

guint
dc_message_history_earlier_batch_start (guint loaded_start,
                                        guint target_index,
                                        guint batch_size)
{
	guint _tmp0_ = 0U;
	guint start = 0U;
	guint result;
	if (target_index >= loaded_start) {
		result = loaded_start;
		return result;
	}
	if (loaded_start > batch_size) {
		_tmp0_ = loaded_start - batch_size;
	} else {
		_tmp0_ = (guint) 0;
	}
	start = _tmp0_;
	result = MAX (start, target_index);
	return result;
}

DcMessageHistory*
dc_message_history_construct (GType object_type)
{
	DcMessageHistory * self = NULL;
	self = (DcMessageHistory*) g_object_new (object_type, NULL);
	return self;
}

DcMessageHistory*
dc_message_history_new (void)
{
	return dc_message_history_construct (DC_TYPE_MESSAGE_HISTORY);
}

static void
dc_message_history_class_init (DcMessageHistoryClass * klass,
                               gpointer klass_data)
{
	dc_message_history_parent_class = g_type_class_peek_parent (klass);
}

static void
dc_message_history_instance_init (DcMessageHistory * self,
                                  gpointer klass)
{
}

static GType
dc_message_history_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcMessageHistoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_message_history_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcMessageHistory), 0, (GInstanceInitFunc) dc_message_history_instance_init, NULL };
	GType dc_message_history_type_id;
	dc_message_history_type_id = g_type_register_static (G_TYPE_OBJECT, "DcMessageHistory", &g_define_type_info, 0);
	return dc_message_history_type_id;
}

GType
dc_message_history_get_type (void)
{
	static volatile gsize dc_message_history_type_id__once = 0;
	if (g_once_init_enter (&dc_message_history_type_id__once)) {
		GType dc_message_history_type_id;
		dc_message_history_type_id = dc_message_history_get_type_once ();
		g_once_init_leave (&dc_message_history_type_id__once, dc_message_history_type_id);
	}
	return dc_message_history_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

