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

/*
 * Copyright (c) 2024-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authors: Kamil Prusko <kamilprusko@gmail.com>
 */

#include "ft_core.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.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

#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _FtParamSpecEventSpec FtParamSpecEventSpec;
#define _ft_event_spec_unref0(var) ((var == NULL) ? NULL : (var = (ft_event_spec_unref (var), NULL)))
#define _ft_context_unref0(var) ((var == NULL) ? NULL : (var = (ft_context_unref (var), NULL)))

struct _FtParamSpecEventSpec {
	GParamSpec parent_instance;
};

static gpointer ft_event_spec_parent_class = NULL;

VALA_EXTERN gboolean ft_trigger_start_event (const FtTimerState* current_state,
                                 const FtTimerState* previous_state);
VALA_EXTERN gboolean ft_trigger_stop_event (const FtTimerState* current_state,
                                const FtTimerState* previous_state);
VALA_EXTERN gboolean ft_trigger_pause_event (const FtTimerState* current_state,
                                 const FtTimerState* previous_state);
VALA_EXTERN gboolean ft_trigger_resume_event (const FtTimerState* current_state,
                                  const FtTimerState* previous_state);
VALA_EXTERN gboolean ft_trigger_rewind_event (const FtTimerState* current_state,
                                  const FtTimerState* previous_state);
VALA_EXTERN gboolean ft_trigger_skip_event (FtSession* current_session,
                                FtTimeBlock* current_time_block,
                                FtSession* previous_session,
                                FtTimeBlock* previous_time_block);
VALA_EXTERN gboolean ft_trigger_reset_event (FtSession* current_session,
                                 FtTimeBlock* current_time_block,
                                 FtSession* previous_session,
                                 FtTimeBlock* previous_time_block);
VALA_EXTERN gboolean ft_trigger_finish_event (const FtTimerState* current_state,
                                  const FtTimerState* previous_state);
VALA_EXTERN gboolean ft_trigger_confirm_advancement_event (FtTimeBlock* next_time_block,
                                               FtTimeBlock* previous_time_block);
VALA_EXTERN gboolean ft_trigger_advance_event (FtSession* current_session,
                                   FtTimeBlock* current_time_block,
                                   FtSession* previous_session,
                                   FtTimeBlock* previous_time_block);
VALA_EXTERN gboolean ft_trigger_change_event (const FtTimerState* current_state,
                                  const FtTimerState* previous_state);
VALA_EXTERN gboolean ft_trigger_state_change_event (FtState current_state,
                                        FtState previous_state);
VALA_EXTERN gboolean ft_trigger_reschedule_event (FtSession* session);
VALA_EXTERN gboolean ft_trigger_expire_event (FtSession* session);
static void _vala_array_add15 (FtTrigger* * array,
                        gint* length,
                        gint* size,
                        const FtTrigger* value);
static void ft_event_spec_finalize (FtEventSpec * obj);
static GType ft_event_spec_get_type_once (void);
static void ft_event_instance_init (FtEvent * self);
VALA_EXTERN void ft_initialize_events (FtEventProducer* producer);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

gboolean
ft_trigger_start_event (const FtTimerState* current_state,
                        const FtTimerState* previous_state)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_ = FALSE;
	FtTimerState _tmp4_;
	void* _tmp5_;
	gboolean result;
	g_return_val_if_fail (current_state != NULL, FALSE);
	g_return_val_if_fail (previous_state != NULL, FALSE);
	_tmp0_ = ft_context_get_event_source ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strcmp0 (_tmp1_, "timer.start") != 0;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		result = FALSE;
		return result;
	}
	_tmp4_ = *current_state;
	_tmp5_ = _tmp4_.user_data;
	if (_tmp5_ != NULL) {
		FtTimerState _tmp6_;
		void* _tmp7_;
		_tmp6_ = *previous_state;
		_tmp7_ = _tmp6_.user_data;
		_tmp3_ = _tmp7_ == NULL;
	} else {
		_tmp3_ = FALSE;
	}
	result = _tmp3_;
	return result;
}

gboolean
ft_trigger_stop_event (const FtTimerState* current_state,
                       const FtTimerState* previous_state)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_ = FALSE;
	FtTimerState _tmp4_;
	void* _tmp5_;
	gboolean result;
	g_return_val_if_fail (current_state != NULL, FALSE);
	g_return_val_if_fail (previous_state != NULL, FALSE);
	_tmp0_ = ft_context_get_event_source ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strcmp0 (_tmp1_, "timer.reset") != 0;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		result = FALSE;
		return result;
	}
	_tmp4_ = *current_state;
	_tmp5_ = _tmp4_.user_data;
	if (_tmp5_ == NULL) {
		FtTimerState _tmp6_;
		void* _tmp7_;
		_tmp6_ = *previous_state;
		_tmp7_ = _tmp6_.user_data;
		_tmp3_ = _tmp7_ != NULL;
	} else {
		_tmp3_ = FALSE;
	}
	result = _tmp3_;
	return result;
}

gboolean
ft_trigger_pause_event (const FtTimerState* current_state,
                        const FtTimerState* previous_state)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	FtTimerState _tmp5_;
	void* _tmp6_;
	FtTimerState _tmp7_;
	void* _tmp8_;
	gboolean result;
	g_return_val_if_fail (current_state != NULL, FALSE);
	g_return_val_if_fail (previous_state != NULL, FALSE);
	_tmp0_ = ft_context_get_event_source ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strcmp0 (_tmp1_, "timer.pause") != 0;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		result = FALSE;
		return result;
	}
	_tmp5_ = *current_state;
	_tmp6_ = _tmp5_.user_data;
	_tmp7_ = *previous_state;
	_tmp8_ = _tmp7_.user_data;
	if (_tmp6_ == _tmp8_) {
		_tmp4_ = ft_timer_state_is_paused (current_state);
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		_tmp3_ = !ft_timer_state_is_paused (previous_state);
	} else {
		_tmp3_ = FALSE;
	}
	result = _tmp3_;
	return result;
}

gboolean
ft_trigger_resume_event (const FtTimerState* current_state,
                         const FtTimerState* previous_state)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	FtTimerState _tmp5_;
	void* _tmp6_;
	FtTimerState _tmp7_;
	void* _tmp8_;
	gboolean result;
	g_return_val_if_fail (current_state != NULL, FALSE);
	g_return_val_if_fail (previous_state != NULL, FALSE);
	_tmp0_ = ft_context_get_event_source ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strcmp0 (_tmp1_, "timer.resume") != 0;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		result = FALSE;
		return result;
	}
	_tmp5_ = *current_state;
	_tmp6_ = _tmp5_.user_data;
	_tmp7_ = *previous_state;
	_tmp8_ = _tmp7_.user_data;
	if (_tmp6_ == _tmp8_) {
		_tmp4_ = !ft_timer_state_is_paused (current_state);
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		_tmp3_ = ft_timer_state_is_paused (previous_state);
	} else {
		_tmp3_ = FALSE;
	}
	result = _tmp3_;
	return result;
}

gboolean
ft_trigger_rewind_event (const FtTimerState* current_state,
                         const FtTimerState* previous_state)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	FtTimerState _tmp5_;
	void* _tmp6_;
	FtTimerState _tmp7_;
	void* _tmp8_;
	gboolean result;
	g_return_val_if_fail (current_state != NULL, FALSE);
	g_return_val_if_fail (previous_state != NULL, FALSE);
	_tmp0_ = ft_context_get_event_source ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strcmp0 (_tmp1_, "timer.rewind") != 0;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		result = FALSE;
		return result;
	}
	_tmp5_ = *current_state;
	_tmp6_ = _tmp5_.user_data;
	_tmp7_ = *previous_state;
	_tmp8_ = _tmp7_.user_data;
	if (_tmp6_ == _tmp8_) {
		FtTimerState _tmp9_;
		FtTimerState _tmp10_;
		_tmp9_ = *current_state;
		_tmp10_ = *previous_state;
		_tmp4_ = _tmp9_.paused_time == _tmp10_.paused_time;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		FtTimerState _tmp11_;
		FtTimerState _tmp12_;
		_tmp11_ = *current_state;
		_tmp12_ = *previous_state;
		_tmp3_ = _tmp11_.offset != _tmp12_.offset;
	} else {
		_tmp3_ = FALSE;
	}
	result = _tmp3_;
	return result;
}

gboolean
ft_trigger_skip_event (FtSession* current_session,
                       FtTimeBlock* current_time_block,
                       FtSession* previous_session,
                       FtTimeBlock* previous_time_block)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	FtState _tmp5_;
	FtState _tmp6_;
	FtState _tmp9_;
	FtState _tmp10_;
	FtState _tmp11_;
	FtState _tmp12_;
	gboolean _tmp13_ = FALSE;
	gboolean result;
	_tmp0_ = ft_context_get_event_source ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strcmp0 (_tmp1_, "session-manager.advance") != 0;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		result = FALSE;
		return result;
	}
	if (current_time_block == NULL) {
		_tmp3_ = TRUE;
	} else {
		_tmp3_ = previous_time_block == NULL;
	}
	if (_tmp3_) {
		result = FALSE;
		return result;
	}
	_tmp5_ = ft_time_block_get_state (current_time_block);
	_tmp6_ = _tmp5_;
	if (_tmp6_ != FT_STATE_POMODORO) {
		FtState _tmp7_;
		FtState _tmp8_;
		_tmp7_ = ft_time_block_get_state (previous_time_block);
		_tmp8_ = _tmp7_;
		_tmp4_ = _tmp8_ != FT_STATE_POMODORO;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		result = FALSE;
		return result;
	}
	_tmp9_ = ft_time_block_get_state (current_time_block);
	_tmp10_ = _tmp9_;
	_tmp11_ = ft_time_block_get_state (previous_time_block);
	_tmp12_ = _tmp11_;
	if (ft_state_is_break (_tmp10_) == ft_state_is_break (_tmp12_)) {
		result = FALSE;
		return result;
	}
	if (ft_time_block_get_status (current_time_block) == FT_TIME_BLOCK_STATUS_IN_PROGRESS) {
		_tmp13_ = ft_time_block_get_status (previous_time_block) == FT_TIME_BLOCK_STATUS_UNCOMPLETED;
	} else {
		_tmp13_ = FALSE;
	}
	result = _tmp13_;
	return result;
}

gboolean
ft_trigger_reset_event (FtSession* current_session,
                        FtTimeBlock* current_time_block,
                        FtSession* previous_session,
                        FtTimeBlock* previous_time_block)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_ = FALSE;
	gboolean result;
	_tmp0_ = ft_context_get_event_source ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strcmp0 (_tmp1_, "session-manager.reset") != 0;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		result = FALSE;
		return result;
	}
	if (current_session == previous_session) {
		_tmp3_ = TRUE;
	} else {
		_tmp3_ = previous_session == NULL;
	}
	if (_tmp3_) {
		result = FALSE;
		return result;
	}
	if (current_session == NULL) {
		result = TRUE;
		return result;
	}
	result = !ft_session_is_completed (previous_session);
	return result;
}

gboolean
ft_trigger_finish_event (const FtTimerState* current_state,
                         const FtTimerState* previous_state)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (current_state != NULL, FALSE);
	g_return_val_if_fail (previous_state != NULL, FALSE);
	if (ft_timer_state_is_finished (current_state)) {
		_tmp0_ = !ft_timer_state_is_finished (previous_state);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

gboolean
ft_trigger_confirm_advancement_event (FtTimeBlock* next_time_block,
                                      FtTimeBlock* previous_time_block)
{
	gboolean result;
	g_return_val_if_fail (next_time_block != NULL, FALSE);
	g_return_val_if_fail (previous_time_block != NULL, FALSE);
	result = TRUE;
	return result;
}

gboolean
ft_trigger_advance_event (FtSession* current_session,
                          FtTimeBlock* current_time_block,
                          FtSession* previous_session,
                          FtTimeBlock* previous_time_block)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	if (current_time_block != NULL) {
		_tmp0_ = previous_time_block != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

gboolean
ft_trigger_change_event (const FtTimerState* current_state,
                         const FtTimerState* previous_state)
{
	gboolean _tmp0_ = FALSE;
	FtTimerState _tmp5_;
	gboolean result;
	g_return_val_if_fail (current_state != NULL, FALSE);
	g_return_val_if_fail (previous_state != NULL, FALSE);
	if (ft_timer_state_is_finished (current_state)) {
		FtTimerState _tmp1_;
		void* _tmp2_;
		FtTimerState _tmp3_;
		void* _tmp4_;
		_tmp1_ = *current_state;
		_tmp2_ = _tmp1_.user_data;
		_tmp3_ = *previous_state;
		_tmp4_ = _tmp3_.user_data;
		_tmp0_ = _tmp2_ == _tmp4_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	_tmp5_ = *previous_state;
	result = !ft_timer_state_equals (current_state, &_tmp5_);
	return result;
}

gboolean
ft_trigger_state_change_event (FtState current_state,
                               FtState previous_state)
{
	gboolean result;
	result = TRUE;
	return result;
}

gboolean
ft_trigger_reschedule_event (FtSession* session)
{
	gboolean result;
	g_return_val_if_fail (session != NULL, FALSE);
	result = TRUE;
	return result;
}

gboolean
ft_trigger_expire_event (FtSession* session)
{
	gboolean result;
	g_return_val_if_fail (session != NULL, FALSE);
	result = TRUE;
	return result;
}

gchar*
ft_event_category_get_label (FtEventCategory self)
{
	gchar* result;
	switch (self) {
		case FT_EVENT_CATEGORY_ACTIONS:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup (_ ("Actions"));
			result = _tmp0_;
			return result;
		}
		case FT_EVENT_CATEGORY_COUNTDOWN:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup (_ ("Countdown"));
			result = _tmp1_;
			return result;
		}
		case FT_EVENT_CATEGORY_SESSION:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup (_ ("Session"));
			result = _tmp2_;
			return result;
		}
		case FT_EVENT_CATEGORY_OTHER:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup (_ ("Other"));
			result = _tmp3_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

void
ft_event_category_foreach (GFunc func,
                           gpointer func_target)
{
	func ((gpointer) ((gintptr) FT_EVENT_CATEGORY_ACTIONS), func_target);
	func ((gpointer) ((gintptr) FT_EVENT_CATEGORY_COUNTDOWN), func_target);
	func ((gpointer) ((gintptr) FT_EVENT_CATEGORY_SESSION), func_target);
	func ((gpointer) ((gintptr) FT_EVENT_CATEGORY_OTHER), func_target);
}

static GType
ft_event_category_get_type_once (void)
{
	static const GEnumValue values[] = {{FT_EVENT_CATEGORY_OTHER, "FT_EVENT_CATEGORY_OTHER", "other"}, {FT_EVENT_CATEGORY_ACTIONS, "FT_EVENT_CATEGORY_ACTIONS", "actions"}, {FT_EVENT_CATEGORY_COUNTDOWN, "FT_EVENT_CATEGORY_COUNTDOWN", "countdown"}, {FT_EVENT_CATEGORY_SESSION, "FT_EVENT_CATEGORY_SESSION", "session"}, {0, NULL, NULL}};
	GType ft_event_category_type_id;
	ft_event_category_type_id = g_enum_register_static ("FtEventCategory", values);
	return ft_event_category_type_id;
}

GType
ft_event_category_get_type (void)
{
	static volatile gsize ft_event_category_type_id__once = 0;
	if (g_once_init_enter (&ft_event_category_type_id__once)) {
		GType ft_event_category_type_id;
		ft_event_category_type_id = ft_event_category_get_type_once ();
		g_once_init_leave (&ft_event_category_type_id__once, ft_event_category_type_id);
	}
	return ft_event_category_type_id__once;
}

FtEventSpec*
ft_event_spec_construct (GType object_type,
                         const gchar* name,
                         const gchar* display_name,
                         const gchar* description,
                         FtEventCategory category)
{
	FtEventSpec* self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	FtTrigger* _tmp3_;
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (display_name != NULL, NULL);
	g_return_val_if_fail (description != NULL, NULL);
	self = (FtEventSpec*) g_type_create_instance (object_type);
	_tmp0_ = g_strdup (name);
	_g_free0 (self->name);
	self->name = _tmp0_;
	_tmp1_ = g_strdup (display_name);
	_g_free0 (self->display_name);
	self->display_name = _tmp1_;
	_tmp2_ = g_strdup (description);
	_g_free0 (self->description);
	self->description = _tmp2_;
	self->category = category;
	_tmp3_ = g_new0 (FtTrigger, 0);
	self->triggers = (g_free (self->triggers), NULL);
	self->triggers = _tmp3_;
	self->triggers_length1 = 0;
	self->_triggers_size_ = self->triggers_length1;
	return self;
}

FtEventSpec*
ft_event_spec_new (const gchar* name,
                   const gchar* display_name,
                   const gchar* description,
                   FtEventCategory category)
{
	return ft_event_spec_construct (FT_TYPE_EVENT_SPEC, name, display_name, description, category);
}

static void
_vala_array_add15 (FtTrigger* * array,
                   gint* length,
                   gint* size,
                   const FtTrigger* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (FtTrigger, *array, *size);
	}
	(*array)[(*length)++] = *value;
}

void
ft_event_spec_add_trigger (FtEventSpec* self,
                           FtTriggerHook trigger_hook,
                           FtTriggerFunc trigger_func)
{
	FtEventSpec* _self_ = NULL;
	FtTrigger _tmp0_ = {0};
	g_return_if_fail (self != NULL);
	_self_ = self;
	memset (&_tmp0_, 0, sizeof (FtTrigger));
	_tmp0_.event_spec = _self_;
	_tmp0_.hook = trigger_hook;
	_tmp0_.func = trigger_func;
	_vala_array_add15 (&self->triggers, &self->triggers_length1, &self->_triggers_size_, &_tmp0_);
}

static void
ft_value_event_spec_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
ft_value_event_spec_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		ft_event_spec_unref (value->data[0].v_pointer);
	}
}

static void
ft_value_event_spec_copy_value (const GValue* src_value,
                                GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = ft_event_spec_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
ft_value_event_spec_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
ft_value_event_spec_collect_value (GValue* value,
                                   guint n_collect_values,
                                   GTypeCValue* collect_values,
                                   guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		FtEventSpec * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = ft_event_spec_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
ft_value_event_spec_lcopy_value (const GValue* value,
                                 guint n_collect_values,
                                 GTypeCValue* collect_values,
                                 guint collect_flags)
{
	FtEventSpec ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = ft_event_spec_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
ft_param_spec_event_spec (const gchar* name,
                          const gchar* nick,
                          const gchar* blurb,
                          GType object_type,
                          GParamFlags flags)
{
	FtParamSpecEventSpec* spec;
	g_return_val_if_fail (g_type_is_a (object_type, FT_TYPE_EVENT_SPEC), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
ft_value_get_event_spec (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, FT_TYPE_EVENT_SPEC), NULL);
	return value->data[0].v_pointer;
}

void
ft_value_set_event_spec (GValue* value,
                         gpointer v_object)
{
	FtEventSpec * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, FT_TYPE_EVENT_SPEC));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, FT_TYPE_EVENT_SPEC));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		ft_event_spec_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		ft_event_spec_unref (old);
	}
}

void
ft_value_take_event_spec (GValue* value,
                          gpointer v_object)
{
	FtEventSpec * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, FT_TYPE_EVENT_SPEC));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, FT_TYPE_EVENT_SPEC));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		ft_event_spec_unref (old);
	}
}

static void
ft_event_spec_class_init (FtEventSpecClass * klass,
                          gpointer klass_data)
{
	ft_event_spec_parent_class = g_type_class_peek_parent (klass);
	((FtEventSpecClass *) klass)->finalize = ft_event_spec_finalize;
}

static void
ft_event_spec_instance_init (FtEventSpec * self,
                             gpointer klass)
{
	self->ref_count = 1;
}

static void
ft_event_spec_finalize (FtEventSpec * obj)
{
	FtEventSpec * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_EVENT_SPEC, FtEventSpec);
	g_signal_handlers_destroy (self);
	_g_free0 (self->name);
	_g_free0 (self->display_name);
	_g_free0 (self->description);
	self->triggers = (g_free (self->triggers), NULL);
}

static GType
ft_event_spec_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { ft_value_event_spec_init, ft_value_event_spec_free_value, ft_value_event_spec_copy_value, ft_value_event_spec_peek_pointer, "p", ft_value_event_spec_collect_value, "p", ft_value_event_spec_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (FtEventSpecClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_event_spec_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtEventSpec), 0, (GInstanceInitFunc) ft_event_spec_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType ft_event_spec_type_id;
	ft_event_spec_type_id = g_type_register_fundamental (g_type_fundamental_next (), "FtEventSpec", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return ft_event_spec_type_id;
}

GType
ft_event_spec_get_type (void)
{
	static volatile gsize ft_event_spec_type_id__once = 0;
	if (g_once_init_enter (&ft_event_spec_type_id__once)) {
		GType ft_event_spec_type_id;
		ft_event_spec_type_id = ft_event_spec_get_type_once ();
		g_once_init_leave (&ft_event_spec_type_id__once, ft_event_spec_type_id);
	}
	return ft_event_spec_type_id__once;
}

gpointer
ft_event_spec_ref (gpointer instance)
{
	FtEventSpec * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
ft_event_spec_unref (gpointer instance)
{
	FtEventSpec * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		FT_EVENT_SPEC_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static gpointer
_ft_event_spec_ref0 (gpointer self)
{
	return self ? ft_event_spec_ref (self) : NULL;
}

static gpointer
_ft_context_ref0 (gpointer self)
{
	return self ? ft_context_ref (self) : NULL;
}

FtEvent*
ft_event_new (FtEventSpec* spec,
              FtContext* context)
{
	FtEvent* self;
	FtEventSpec* _tmp0_;
	FtContext* _tmp1_;
	g_return_val_if_fail (spec != NULL, NULL);
	g_return_val_if_fail (context != NULL, NULL);
	self = g_slice_new0 (FtEvent);
	ft_event_instance_init (self);
	_tmp0_ = _ft_event_spec_ref0 (spec);
	_ft_event_spec_unref0 (self->spec);
	self->spec = _tmp0_;
	_tmp1_ = _ft_context_ref0 (context);
	_ft_context_unref0 (self->context);
	self->context = _tmp1_;
	return self;
}

static void
ft_event_instance_init (FtEvent * self)
{
}

void
ft_event_free (FtEvent * self)
{
	_ft_event_spec_unref0 (self->spec);
	self->spec = NULL;
	_ft_context_unref0 (self->context);
	self->context = NULL;
	_ft_event_spec_unref0 (self->spec);
	_ft_context_unref0 (self->context);
	g_slice_free (FtEvent, self);
}

void
ft_initialize_events (FtEventProducer* producer)
{
	FtEventSpec* event_spec = NULL;
	FtEventSpec* _tmp0_;
	FtEventSpec* _tmp1_;
	FtEventSpec* _tmp2_;
	FtEventSpec* _tmp3_;
	FtEventSpec* _tmp4_;
	FtEventSpec* _tmp5_;
	FtEventSpec* _tmp6_;
	FtEventSpec* _tmp7_;
	FtEventSpec* _tmp8_;
	FtEventSpec* _tmp9_;
	FtEventSpec* _tmp10_;
	FtEventSpec* _tmp11_;
	FtEventSpec* _tmp12_;
	FtEventSpec* _tmp13_;
	FtEventSpec* _tmp14_;
	FtEventSpec* _tmp15_;
	FtEventSpec* _tmp16_;
	FtEventSpec* _tmp17_;
	FtEventSpec* _tmp18_;
	FtEventSpec* _tmp19_;
	FtEventSpec* _tmp20_;
	FtEventSpec* _tmp21_;
	FtEventSpec* _tmp22_;
	FtEventSpec* _tmp23_;
	FtEventSpec* _tmp24_;
	FtEventSpec* _tmp25_;
	FtEventSpec* _tmp26_;
	FtEventSpec* _tmp27_;
	FtEventSpec* _tmp28_;
	FtEventSpec* _tmp29_;
	FtEventSpec* _tmp30_;
	FtEventSpec* _tmp31_;
	FtEventSpec* _tmp32_;
	FtEventSpec* _tmp33_;
	FtEventSpec* _tmp34_;
	FtEventSpec* _tmp35_;
	FtEventSpec* _tmp36_;
	FtEventSpec* _tmp37_;
	FtEventSpec* _tmp38_;
	FtEventSpec* _tmp39_;
	FtEventSpec* _tmp40_;
	FtEventSpec* _tmp41_;
	g_return_if_fail (producer != NULL);
	_tmp0_ = ft_event_spec_new ("start", _ ("Start"), _ ("Started the timer."), FT_EVENT_CATEGORY_ACTIONS);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp0_;
	_tmp1_ = event_spec;
	ft_event_spec_add_trigger (_tmp1_, FT_TRIGGER_HOOK_TIMER_STATE_CHANGED, (FtTriggerFunc) ft_trigger_start_event);
	_tmp2_ = event_spec;
	ft_event_producer_install_event (producer, _tmp2_);
	_tmp3_ = ft_event_spec_new ("stop", _ ("Stop"), _ ("Stopped the timer manually."), FT_EVENT_CATEGORY_ACTIONS);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp3_;
	_tmp4_ = event_spec;
	ft_event_spec_add_trigger (_tmp4_, FT_TRIGGER_HOOK_TIMER_STATE_CHANGED, (FtTriggerFunc) ft_trigger_stop_event);
	_tmp5_ = event_spec;
	ft_event_producer_install_event (producer, _tmp5_);
	_tmp6_ = ft_event_spec_new ("pause", _ ("Pause"), _ ("The countdown has been manually paused. Not triggered when locking the" \
" screen or when suspending the system."), FT_EVENT_CATEGORY_ACTIONS);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp6_;
	_tmp7_ = event_spec;
	ft_event_spec_add_trigger (_tmp7_, FT_TRIGGER_HOOK_TIMER_STATE_CHANGED, (FtTriggerFunc) ft_trigger_pause_event);
	_tmp8_ = event_spec;
	ft_event_producer_install_event (producer, _tmp8_);
	_tmp9_ = ft_event_spec_new ("resume", _ ("Resume"), _ ("The countdown has been manually resumed."), FT_EVENT_CATEGORY_ACTIONS);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp9_;
	_tmp10_ = event_spec;
	ft_event_spec_add_trigger (_tmp10_, FT_TRIGGER_HOOK_TIMER_STATE_CHANGED, (FtTriggerFunc) ft_trigger_resume_event);
	_tmp11_ = event_spec;
	ft_event_producer_install_event (producer, _tmp11_);
	_tmp12_ = ft_event_spec_new ("skip", _ ("Skip"), _ ("Jumped to a next time-block before the countdown has finished."), FT_EVENT_CATEGORY_ACTIONS);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp12_;
	_tmp13_ = event_spec;
	ft_event_spec_add_trigger (_tmp13_, FT_TRIGGER_HOOK_SESSION_MANAGER_ADVANCED, (FtTriggerFunc) ft_trigger_skip_event);
	_tmp14_ = event_spec;
	ft_event_producer_install_event (producer, _tmp14_);
	_tmp15_ = ft_event_spec_new ("rewind", _ ("Rewind"), _ ("Rewind action has been used. It adds a pause in the past."), FT_EVENT_CATEGORY_ACTIONS);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp15_;
	_tmp16_ = event_spec;
	ft_event_spec_add_trigger (_tmp16_, FT_TRIGGER_HOOK_TIMER_STATE_CHANGED, (FtTriggerFunc) ft_trigger_rewind_event);
	_tmp17_ = event_spec;
	ft_event_producer_install_event (producer, _tmp17_);
	_tmp18_ = ft_event_spec_new ("reset", _ ("Reset"), _ ("Manually cleared the session."), FT_EVENT_CATEGORY_ACTIONS);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp18_;
	_tmp19_ = event_spec;
	ft_event_spec_add_trigger (_tmp19_, FT_TRIGGER_HOOK_SESSION_MANAGER_ADVANCED, (FtTriggerFunc) ft_trigger_reset_event);
	_tmp20_ = event_spec;
	ft_event_producer_install_event (producer, _tmp20_);
	_tmp21_ = ft_event_spec_new ("finish", _ ("Finished"), _ ("The countdown has finished. If waiting for confirmation, the duration " \
"of the time-block still may be altered."), FT_EVENT_CATEGORY_COUNTDOWN);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp21_;
	_tmp22_ = event_spec;
	ft_event_spec_add_trigger (_tmp22_, FT_TRIGGER_HOOK_TIMER_STATE_CHANGED, (FtTriggerFunc) ft_trigger_finish_event);
	_tmp23_ = event_spec;
	ft_event_producer_install_event (producer, _tmp23_);
	_tmp24_ = ft_event_spec_new ("change", _ ("Changed"), _ ("Triggered on any change related to the countdown."), FT_EVENT_CATEGORY_COUNTDOWN);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp24_;
	_tmp25_ = event_spec;
	ft_event_spec_add_trigger (_tmp25_, FT_TRIGGER_HOOK_TIMER_STATE_CHANGED, (FtTriggerFunc) ft_trigger_change_event);
	_tmp26_ = event_spec;
	ft_event_producer_install_event (producer, _tmp26_);
	_tmp27_ = ft_event_spec_new ("confirm-advancement", _ ("Confirm Advancement"), _ ("A manual confirmation is required to start next time-block."), FT_EVENT_CATEGORY_SESSION);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp27_;
	_tmp28_ = event_spec;
	ft_event_spec_add_trigger (_tmp28_, FT_TRIGGER_HOOK_SESSION_MANAGER_CONFIRM_ADVANCEMENT, (FtTriggerFunc) ft_trigger_confirm_advancement_event);
	_tmp29_ = event_spec;
	ft_event_producer_install_event (producer, _tmp29_);
	_tmp30_ = ft_event_spec_new ("advance", _ ("Advanced"), _ ("Transitioned or skipped to a next time-block."), FT_EVENT_CATEGORY_SESSION);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp30_;
	_tmp31_ = event_spec;
	ft_event_spec_add_trigger (_tmp31_, FT_TRIGGER_HOOK_SESSION_MANAGER_ADVANCED, (FtTriggerFunc) ft_trigger_advance_event);
	_tmp32_ = event_spec;
	ft_event_producer_install_event (producer, _tmp32_);
	_tmp33_ = ft_event_spec_new ("state-change", _ ("State Changed"), _ ("Transitioned to a next time-block or when a break gets relabelled."), FT_EVENT_CATEGORY_SESSION);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp33_;
	_tmp34_ = event_spec;
	ft_event_spec_add_trigger (_tmp34_, FT_TRIGGER_HOOK_SESSION_MANAGER_NOTIFY_CURRENT_STATE, (FtTriggerFunc) ft_trigger_state_change_event);
	_tmp35_ = event_spec;
	ft_event_producer_install_event (producer, _tmp35_);
	_tmp36_ = ft_event_spec_new ("reschedule", _ ("Rescheduled"), _ ("Triggered when scheduled time-blocks have changed."), FT_EVENT_CATEGORY_SESSION);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp36_;
	_tmp37_ = event_spec;
	ft_event_spec_add_trigger (_tmp37_, FT_TRIGGER_HOOK_SESSION_MANAGER_SESSION_RESCHEDULED, (FtTriggerFunc) ft_trigger_reschedule_event);
	_tmp38_ = event_spec;
	ft_event_producer_install_event (producer, _tmp38_);
	_tmp39_ = ft_event_spec_new ("expire", _ ("Expired"), _ ("Triggered when session is about to be reset due to inactivity."), FT_EVENT_CATEGORY_SESSION);
	_ft_event_spec_unref0 (event_spec);
	event_spec = _tmp39_;
	_tmp40_ = event_spec;
	ft_event_spec_add_trigger (_tmp40_, FT_TRIGGER_HOOK_SESSION_MANAGER_SESSION_EXPIRED, (FtTriggerFunc) ft_trigger_expire_event);
	_tmp41_ = event_spec;
	ft_event_producer_install_event (producer, _tmp41_);
	_ft_event_spec_unref0 (event_spec);
}

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

