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

/*
 * Copyright (c) 2021-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

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

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

/**
     * Ft.State
     *
     * In general, there are main states STOPPED, POMODORO and BREAK.
     * BREAK may be resolved to either SHORT_BREAK or LONG_BREAK by the session-manager / scheduler,
     * but can function on its own if session has no cycles.
     */
gchar*
ft_state_to_string (FtState self)
{
	gchar* result;
	switch (self) {
		case FT_STATE_STOPPED:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("stopped");
			result = _tmp0_;
			return result;
		}
		case FT_STATE_POMODORO:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("pomodoro");
			result = _tmp1_;
			return result;
		}
		case FT_STATE_BREAK:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("break");
			result = _tmp2_;
			return result;
		}
		case FT_STATE_SHORT_BREAK:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("short-break");
			result = _tmp3_;
			return result;
		}
		case FT_STATE_LONG_BREAK:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("long-break");
			result = _tmp4_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

FtState
ft_state_from_string (const gchar* state)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	FtState result;
	_tmp0_ = state;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("pomodoro")))) {
		switch (0) {
			default:
			{
				result = FT_STATE_POMODORO;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("break")))) {
		switch (0) {
			default:
			{
				result = FT_STATE_BREAK;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("short-break")))) {
		switch (0) {
			default:
			{
				result = FT_STATE_SHORT_BREAK;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("long-break")))) {
		switch (0) {
			default:
			{
				result = FT_STATE_LONG_BREAK;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				result = FT_STATE_STOPPED;
				return result;
			}
		}
	}
}

gchar*
ft_state_get_label (FtState self)
{
	gchar* result;
	switch (self) {
		case FT_STATE_STOPPED:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup (_ ("Stopped"));
			result = _tmp0_;
			return result;
		}
		case FT_STATE_POMODORO:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup (_ ("Pomodoro"));
			result = _tmp1_;
			return result;
		}
		case FT_STATE_BREAK:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup (_ ("Break"));
			result = _tmp2_;
			return result;
		}
		case FT_STATE_SHORT_BREAK:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup (_ ("Short Break"));
			result = _tmp3_;
			return result;
		}
		case FT_STATE_LONG_BREAK:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup (_ ("Long Break"));
			result = _tmp4_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

gboolean
ft_state_is_a (FtState self,
               FtState other)
{
	gboolean result;
	if (self == FT_STATE_BREAK) {
		result = ft_state_is_break (other);
		return result;
	}
	if (other == FT_STATE_BREAK) {
		result = ft_state_is_break (self);
		return result;
	}
	result = self == other;
	return result;
}

gboolean
ft_state_is_break (FtState self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	if (self == FT_STATE_BREAK) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = self == FT_STATE_SHORT_BREAK;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self == FT_STATE_LONG_BREAK;
	}
	result = _tmp0_;
	return result;
}

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

gint64
ft_state_get_default_duration (FtState self)
{
	GSettings* settings = NULL;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	guint seconds = 0U;
	gint64 result;
	_tmp0_ = ft_get_settings ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	settings = _tmp1_;
	switch (self) {
		case FT_STATE_POMODORO:
		{
			GSettings* _tmp2_;
			_tmp2_ = settings;
			seconds = g_settings_get_uint (_tmp2_, "pomodoro-duration");
			break;
		}
		case FT_STATE_BREAK:
		case FT_STATE_SHORT_BREAK:
		{
			GSettings* _tmp3_;
			_tmp3_ = settings;
			seconds = g_settings_get_uint (_tmp3_, "short-break-duration");
			break;
		}
		case FT_STATE_LONG_BREAK:
		{
			GSettings* _tmp4_;
			_tmp4_ = settings;
			seconds = g_settings_get_uint (_tmp4_, "long-break-duration");
			break;
		}
		default:
		{
			seconds = (guint) 0;
			break;
		}
	}
	result = ((gint64) seconds) * FT_INTERVAL_SECOND;
	_g_object_unref0 (settings);
	return result;
}

static GType
ft_state_get_type_once (void)
{
	static const GEnumValue values[] = {{FT_STATE_STOPPED, "FT_STATE_STOPPED", "stopped"}, {FT_STATE_POMODORO, "FT_STATE_POMODORO", "pomodoro"}, {FT_STATE_BREAK, "FT_STATE_BREAK", "break"}, {FT_STATE_SHORT_BREAK, "FT_STATE_SHORT_BREAK", "short-break"}, {FT_STATE_LONG_BREAK, "FT_STATE_LONG_BREAK", "long-break"}, {0, NULL, NULL}};
	GType ft_state_type_id;
	ft_state_type_id = g_enum_register_static ("FtState", values);
	return ft_state_type_id;
}

GType
ft_state_get_type (void)
{
	static volatile gsize ft_state_type_id__once = 0;
	if (g_once_init_enter (&ft_state_type_id__once)) {
		GType ft_state_type_id;
		ft_state_type_id = ft_state_get_type_once ();
		g_once_init_leave (&ft_state_type_id__once, ft_state_type_id);
	}
	return ft_state_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;
}

