/* provider.c generated by valac 0.56.19, the Vala compiler
 * generated from provider.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 <gio/gio.h>
#include <glib-object.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

enum  {
	FT_PROVIDER_0_PROPERTY,
	FT_PROVIDER_AVAILABLE_PROPERTY,
	FT_PROVIDER_AVAILABLE_SET_PROPERTY,
	FT_PROVIDER_ENABLED_PROPERTY,
	FT_PROVIDER_NUM_PROPERTIES
};
static GParamSpec* ft_provider_properties[FT_PROVIDER_NUM_PROPERTIES];

struct _FtProviderPrivate {
	gboolean _available;
	gboolean _available_set;
	gboolean _enabled;
};

static gint FtProvider_private_offset;
static gpointer ft_provider_parent_class = NULL;

VALA_EXTERN void ft_provider_set_enabled (FtProvider* self,
                              gboolean value);
static void ft_provider_finalize (GObject * obj);
static GType ft_provider_get_type_once (void);
static void _vala_ft_provider_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec);
static void _vala_ft_provider_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
ft_provider_get_instance_private (FtProvider* self)
{
	return G_STRUCT_MEMBER_P (self, FtProvider_private_offset);
}

void
ft_provider_initialize (FtProvider* self,
                        GCancellable* cancellable,
                        GAsyncReadyCallback _callback_,
                        gpointer _user_data_)
{
	FtProviderClass* _klass_;
	_klass_ = FT_PROVIDER_GET_CLASS (self);
	if (_klass_->initialize) {
		_klass_->initialize (self, cancellable, _callback_, _user_data_);
	}
}

void
ft_provider_initialize_finish (FtProvider* self,
                               GAsyncResult* _res_,
                               GError** error)
{
	FtProviderClass* _klass_;
	_klass_ = FT_PROVIDER_GET_CLASS (self);
	if (_klass_->initialize_finish) {
		_klass_->initialize_finish (self, _res_, error);
	}
}

void
ft_provider_uninitialize (FtProvider* self,
                          GAsyncReadyCallback _callback_,
                          gpointer _user_data_)
{
	FtProviderClass* _klass_;
	_klass_ = FT_PROVIDER_GET_CLASS (self);
	if (_klass_->uninitialize) {
		_klass_->uninitialize (self, _callback_, _user_data_);
	}
}

void
ft_provider_uninitialize_finish (FtProvider* self,
                                 GAsyncResult* _res_,
                                 GError** error)
{
	FtProviderClass* _klass_;
	_klass_ = FT_PROVIDER_GET_CLASS (self);
	if (_klass_->uninitialize_finish) {
		_klass_->uninitialize_finish (self, _res_, error);
	}
}

void
ft_provider_enable (FtProvider* self,
                    GCancellable* cancellable,
                    GAsyncReadyCallback _callback_,
                    gpointer _user_data_)
{
	FtProviderClass* _klass_;
	_klass_ = FT_PROVIDER_GET_CLASS (self);
	if (_klass_->enable) {
		_klass_->enable (self, cancellable, _callback_, _user_data_);
	}
}

void
ft_provider_enable_finish (FtProvider* self,
                           GAsyncResult* _res_,
                           GError** error)
{
	FtProviderClass* _klass_;
	_klass_ = FT_PROVIDER_GET_CLASS (self);
	if (_klass_->enable_finish) {
		_klass_->enable_finish (self, _res_, error);
	}
}

void
ft_provider_disable (FtProvider* self,
                     GAsyncReadyCallback _callback_,
                     gpointer _user_data_)
{
	FtProviderClass* _klass_;
	_klass_ = FT_PROVIDER_GET_CLASS (self);
	if (_klass_->disable) {
		_klass_->disable (self, _callback_, _user_data_);
	}
}

void
ft_provider_disable_finish (FtProvider* self,
                            GAsyncResult* _res_,
                            GError** error)
{
	FtProviderClass* _klass_;
	_klass_ = FT_PROVIDER_GET_CLASS (self);
	if (_klass_->disable_finish) {
		_klass_->disable_finish (self, _res_, error);
	}
}

FtProvider*
ft_provider_construct (GType object_type)
{
	FtProvider * self = NULL;
	self = (FtProvider*) g_object_new (object_type, NULL);
	return self;
}

gboolean
ft_provider_get_available (FtProvider* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_available;
	return result;
}

void
ft_provider_set_available (FtProvider* self,
                           gboolean value)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (self->priv->_available != value) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = !self->priv->_available_set;
	}
	if (_tmp0_) {
		gboolean available_set_changed = FALSE;
		available_set_changed = !self->priv->_available_set;
		self->priv->_available = value;
		self->priv->_available_set = TRUE;
		g_object_notify ((GObject*) self, "available");
		if (available_set_changed) {
			g_object_notify ((GObject*) self, "available-set");
		}
	}
}

gboolean
ft_provider_get_available_set (FtProvider* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_available_set;
	return result;
}

gboolean
ft_provider_get_enabled (FtProvider* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_enabled;
	return result;
}

void
ft_provider_set_enabled (FtProvider* self,
                         gboolean value)
{
	g_return_if_fail (self != NULL);
	if (self->priv->_enabled != value) {
		self->priv->_enabled = value;
		g_object_notify ((GObject*) self, "enabled");
	}
}

static void
ft_provider_class_init (FtProviderClass * klass,
                        gpointer klass_data)
{
	ft_provider_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtProvider_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_provider_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_provider_set_property;
	G_OBJECT_CLASS (klass)->finalize = ft_provider_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_PROVIDER_AVAILABLE_PROPERTY, ft_provider_properties[FT_PROVIDER_AVAILABLE_PROPERTY] = g_param_spec_boolean ("available", "available", "available", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_PROVIDER_AVAILABLE_SET_PROPERTY, ft_provider_properties[FT_PROVIDER_AVAILABLE_SET_PROPERTY] = g_param_spec_boolean ("available-set", "available-set", "available-set", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_PROVIDER_ENABLED_PROPERTY, ft_provider_properties[FT_PROVIDER_ENABLED_PROPERTY] = g_param_spec_boolean ("enabled", "enabled", "enabled", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
}

static void
ft_provider_instance_init (FtProvider * self,
                           gpointer klass)
{
	self->priv = ft_provider_get_instance_private (self);
	self->priv->_available = FALSE;
	self->priv->_available_set = FALSE;
	self->priv->_enabled = FALSE;
}

static void
ft_provider_finalize (GObject * obj)
{
	FtProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_PROVIDER, FtProvider);
	G_OBJECT_CLASS (ft_provider_parent_class)->finalize (obj);
}

/**
     * Provider class helps integrating with an external service. Unlike capabilities which may be enabled/disabled
     * according to settings, providers are enabled according to use. Another difference: for a capability
     * enable/disable operations should be trivial and always be successful, for providers it needs error handling.
     *
     * Subclass should contain implementation. To use it look at `ProviderSet`.
     */
static GType
ft_provider_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtProvider), 0, (GInstanceInitFunc) ft_provider_instance_init, NULL };
	GType ft_provider_type_id;
	ft_provider_type_id = g_type_register_static (G_TYPE_OBJECT, "FtProvider", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	FtProvider_private_offset = g_type_add_instance_private (ft_provider_type_id, sizeof (FtProviderPrivate));
	return ft_provider_type_id;
}

GType
ft_provider_get_type (void)
{
	static volatile gsize ft_provider_type_id__once = 0;
	if (g_once_init_enter (&ft_provider_type_id__once)) {
		GType ft_provider_type_id;
		ft_provider_type_id = ft_provider_get_type_once ();
		g_once_init_leave (&ft_provider_type_id__once, ft_provider_type_id);
	}
	return ft_provider_type_id__once;
}

static void
_vala_ft_provider_get_property (GObject * object,
                                guint property_id,
                                GValue * value,
                                GParamSpec * pspec)
{
	FtProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_PROVIDER, FtProvider);
	switch (property_id) {
		case FT_PROVIDER_AVAILABLE_PROPERTY:
		g_value_set_boolean (value, ft_provider_get_available (self));
		break;
		case FT_PROVIDER_AVAILABLE_SET_PROPERTY:
		g_value_set_boolean (value, ft_provider_get_available_set (self));
		break;
		case FT_PROVIDER_ENABLED_PROPERTY:
		g_value_set_boolean (value, ft_provider_get_enabled (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_provider_set_property (GObject * object,
                                guint property_id,
                                const GValue * value,
                                GParamSpec * pspec)
{
	FtProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_PROVIDER, FtProvider);
	switch (property_id) {
		case FT_PROVIDER_AVAILABLE_PROPERTY:
		ft_provider_set_available (self, g_value_get_boolean (value));
		break;
		case FT_PROVIDER_ENABLED_PROPERTY:
		ft_provider_set_enabled (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

