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

/*
 * Copyright © 2025 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 "chrono.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.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  {
	CHRONO_CORE_0_PROPERTY,
	CHRONO_CORE_NUM_PROPERTIES
};
static GParamSpec* chrono_core_properties[CHRONO_CORE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _ChronoCorePrivate {
	ChronoParser* parser;
	gchar* language;
};

static gint ChronoCore_private_offset;
static gpointer chrono_core_parent_class = NULL;

static void chrono_core_finalize (GObject * obj);
static GType chrono_core_get_type_once (void);

static inline gpointer
chrono_core_get_instance_private (ChronoCore* self)
{
	return G_STRUCT_MEMBER_P (self, ChronoCore_private_offset);
}

/**
         * Creates a new Chrono instance.
         *
         * @param language BCP 47 language code. Supported: ``en``, ``es``.
         */
ChronoCore*
chrono_core_construct (GType object_type,
                       const gchar* language)
{
	ChronoCore * self = NULL;
	gchar* _tmp0_;
	ChronoParser* _tmp1_;
	g_return_val_if_fail (language != NULL, NULL);
	self = (ChronoCore*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (language);
	_g_free0 (self->priv->language);
	self->priv->language = _tmp0_;
	_tmp1_ = chrono_parser_new ();
	_g_object_unref0 (self->priv->parser);
	self->priv->parser = _tmp1_;
	return self;
}

ChronoCore*
chrono_core_new (const gchar* language)
{
	return chrono_core_construct (CHRONO_TYPE_CORE, language);
}

/**
         * Parses a natural language string and returns the first date/time found.
         *
         * @param text The input string to parse (e.g. "tomorrow", "next Monday at 3pm").
         * @param parse_recurrence Whether to also parse recurrence rules (e.g. "every week").
         * @return A {@link ParseResult} with the matched date, or ``null`` if nothing was found.
         */
ChronoParseResult*
chrono_core_parse (ChronoCore* self,
                   const gchar* text,
                   gboolean parse_recurrence)
{
	ChronoParser* _tmp0_;
	const gchar* _tmp1_;
	ChronoParseResult* _tmp2_;
	ChronoParseResult* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (text != NULL, NULL);
	_tmp0_ = self->priv->parser;
	_tmp1_ = self->priv->language;
	_tmp2_ = chrono_parser_parse (_tmp0_, text, _tmp1_, parse_recurrence);
	result = _tmp2_;
	return result;
}

static void
chrono_core_class_init (ChronoCoreClass * klass,
                        gpointer klass_data)
{
	chrono_core_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ChronoCore_private_offset);
	G_OBJECT_CLASS (klass)->finalize = chrono_core_finalize;
}

static void
chrono_core_instance_init (ChronoCore * self,
                           gpointer klass)
{
	self->priv = chrono_core_get_instance_private (self);
}

static void
chrono_core_finalize (GObject * obj)
{
	ChronoCore * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CHRONO_TYPE_CORE, ChronoCore);
	_g_object_unref0 (self->priv->parser);
	_g_free0 (self->priv->language);
	G_OBJECT_CLASS (chrono_core_parent_class)->finalize (obj);
}

/**
     * Entry point for natural language date and time parsing.
     *
     * {{{
     * var chrono = new Chrono.Core ();
     * var result = chrono.parse ("tomorrow at 9am");
     * if (result != null) {
     *     print (result.date.to_string ());
     * }
     * }}}
     */
 G_GNUC_NO_INLINE static GType
chrono_core_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ChronoCoreClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) chrono_core_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ChronoCore), 0, (GInstanceInitFunc) chrono_core_instance_init, NULL };
	GType chrono_core_type_id;
	chrono_core_type_id = g_type_register_static (G_TYPE_OBJECT, "ChronoCore", &g_define_type_info, 0);
	ChronoCore_private_offset = g_type_add_instance_private (chrono_core_type_id, sizeof (ChronoCorePrivate));
	return chrono_core_type_id;
}

GType
chrono_core_get_type (void)
{
	static gsize chrono_core_type_id__once = 0;
	if (g_once_init_enter (&chrono_core_type_id__once)) {
		GType chrono_core_type_id;
		chrono_core_type_id = chrono_core_get_type_once ();
		g_once_init_leave (&chrono_core_type_id__once, chrono_core_type_id);
	}
	return chrono_core_type_id__once;
}

