/* EnglishParser.c generated by valac 0.56.19, the Vala compiler
 * generated from EnglishParser.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_ENGLISH_PARSER_0_PROPERTY,
	CHRONO_ENGLISH_PARSER_NUM_PROPERTIES
};
static GParamSpec* chrono_english_parser_properties[CHRONO_ENGLISH_PARSER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))

struct _ChronoEnglishParserPrivate {
	ChronoENRecurrenceParser* recurrence_parser;
	ChronoENDateTimeComboParser* combo_parser;
	ChronoISOParser* iso_parser;
	ChronoSlashParser* slash_parser;
	ChronoTimeParser* time_parser;
	ChronoENCasualDateParser* casual_parser;
	ChronoENCasualTimeParser* casual_time_parser;
	ChronoENMonthNameParser* month_parser;
	ChronoENRelativeDateFormatParser* relative_parser;
	ChronoENTimeExpressionParser* time_expr_parser;
};

static gint ChronoEnglishParser_private_offset;
static gpointer chrono_english_parser_parent_class = NULL;

static ChronoParseResult* chrono_english_parser_real_parse (ChronoLanguageParser* base,
                                                     const gchar* text,
                                                     gboolean parse_recurrence);
static void chrono_english_parser_finalize (GObject * obj);
static GType chrono_english_parser_get_type_once (void);

static inline gpointer
chrono_english_parser_get_instance_private (ChronoEnglishParser* self)
{
	return G_STRUCT_MEMBER_P (self, ChronoEnglishParser_private_offset);
}

ChronoEnglishParser*
chrono_english_parser_construct (GType object_type)
{
	ChronoEnglishParser * self = NULL;
	ChronoENRecurrenceParser* _tmp0_;
	ChronoENDateTimeComboParser* _tmp1_;
	ChronoISOParser* _tmp2_;
	ChronoSlashParser* _tmp3_;
	ChronoTimeParser* _tmp4_;
	ChronoENCasualDateParser* _tmp5_;
	ChronoENCasualTimeParser* _tmp6_;
	ChronoENMonthNameParser* _tmp7_;
	ChronoENRelativeDateFormatParser* _tmp8_;
	ChronoENTimeExpressionParser* _tmp9_;
	self = (ChronoEnglishParser*) chrono_language_parser_construct (object_type);
	_tmp0_ = chrono_en_recurrence_parser_new ();
	_g_object_unref0 (self->priv->recurrence_parser);
	self->priv->recurrence_parser = _tmp0_;
	_tmp1_ = chrono_en_date_time_combo_parser_new ();
	_g_object_unref0 (self->priv->combo_parser);
	self->priv->combo_parser = _tmp1_;
	_tmp2_ = chrono_iso_parser_new ();
	_g_object_unref0 (self->priv->iso_parser);
	self->priv->iso_parser = _tmp2_;
	_tmp3_ = chrono_slash_parser_new ();
	_g_object_unref0 (self->priv->slash_parser);
	self->priv->slash_parser = _tmp3_;
	_tmp4_ = chrono_time_parser_new ();
	_g_object_unref0 (self->priv->time_parser);
	self->priv->time_parser = _tmp4_;
	_tmp5_ = chrono_en_casual_date_parser_new ();
	_g_object_unref0 (self->priv->casual_parser);
	self->priv->casual_parser = _tmp5_;
	_tmp6_ = chrono_en_casual_time_parser_new ();
	_g_object_unref0 (self->priv->casual_time_parser);
	self->priv->casual_time_parser = _tmp6_;
	_tmp7_ = chrono_en_month_name_parser_new ();
	_g_object_unref0 (self->priv->month_parser);
	self->priv->month_parser = _tmp7_;
	_tmp8_ = chrono_en_relative_date_format_parser_new ();
	_g_object_unref0 (self->priv->relative_parser);
	self->priv->relative_parser = _tmp8_;
	_tmp9_ = chrono_en_time_expression_parser_new ();
	_g_object_unref0 (self->priv->time_expr_parser);
	self->priv->time_expr_parser = _tmp9_;
	return self;
}

ChronoEnglishParser*
chrono_english_parser_new (void)
{
	return chrono_english_parser_construct (CHRONO_TYPE_ENGLISH_PARSER);
}

static ChronoParseResult*
chrono_english_parser_real_parse (ChronoLanguageParser* base,
                                  const gchar* text,
                                  gboolean parse_recurrence)
{
	ChronoEnglishParser * self;
	ChronoParseResult* _result_ = NULL;
	ChronoENDateTimeComboParser* _tmp5_;
	ChronoParseResult* _tmp6_;
	ChronoParseResult* _tmp7_;
	ChronoISOParser* _tmp8_;
	ChronoParseResult* _tmp9_;
	ChronoParseResult* _tmp10_;
	ChronoSlashParser* _tmp11_;
	ChronoParseResult* _tmp12_;
	ChronoParseResult* _tmp13_;
	ChronoTimeParser* _tmp14_;
	ChronoParseResult* _tmp15_;
	ChronoParseResult* _tmp16_;
	ChronoENCasualDateParser* _tmp17_;
	ChronoParseResult* _tmp18_;
	ChronoParseResult* _tmp19_;
	ChronoENCasualTimeParser* _tmp20_;
	ChronoParseResult* _tmp21_;
	ChronoParseResult* _tmp22_;
	ChronoENMonthNameParser* _tmp23_;
	ChronoParseResult* _tmp24_;
	ChronoParseResult* _tmp25_;
	ChronoENRelativeDateFormatParser* _tmp26_;
	ChronoParseResult* _tmp27_;
	ChronoParseResult* _tmp28_;
	ChronoENTimeExpressionParser* _tmp29_;
	ChronoParseResult* _tmp30_;
	ChronoParseResult* _tmp31_;
	ChronoParseResult* result;
	self = (ChronoEnglishParser*) base;
	g_return_val_if_fail (text != NULL, NULL);
	_result_ = NULL;
	if (parse_recurrence) {
		ChronoENRecurrenceParser* _tmp0_;
		GDateTime* _tmp1_;
		GDateTime* _tmp2_;
		ChronoParseResult* _tmp3_;
		ChronoParseResult* _tmp4_;
		_tmp0_ = self->priv->recurrence_parser;
		_tmp1_ = g_date_time_new_now_local ();
		_tmp2_ = _tmp1_;
		_tmp3_ = chrono_en_recurrence_parser_parse (_tmp0_, text, _tmp2_);
		_g_object_unref0 (_result_);
		_result_ = _tmp3_;
		_g_date_time_unref0 (_tmp2_);
		_tmp4_ = _result_;
		if (_tmp4_ != NULL) {
			result = _result_;
			return result;
		}
	}
	_tmp5_ = self->priv->combo_parser;
	_tmp6_ = chrono_en_date_time_combo_parser_parse (_tmp5_, text);
	_g_object_unref0 (_result_);
	_result_ = _tmp6_;
	_tmp7_ = _result_;
	if (_tmp7_ != NULL) {
		result = _result_;
		return result;
	}
	_tmp8_ = self->priv->iso_parser;
	_tmp9_ = chrono_iso_parser_parse (_tmp8_, text);
	_g_object_unref0 (_result_);
	_result_ = _tmp9_;
	_tmp10_ = _result_;
	if (_tmp10_ != NULL) {
		result = _result_;
		return result;
	}
	_tmp11_ = self->priv->slash_parser;
	_tmp12_ = chrono_slash_parser_parse (_tmp11_, text);
	_g_object_unref0 (_result_);
	_result_ = _tmp12_;
	_tmp13_ = _result_;
	if (_tmp13_ != NULL) {
		result = _result_;
		return result;
	}
	_tmp14_ = self->priv->time_parser;
	_tmp15_ = chrono_time_parser_parse (_tmp14_, text);
	_g_object_unref0 (_result_);
	_result_ = _tmp15_;
	_tmp16_ = _result_;
	if (_tmp16_ != NULL) {
		result = _result_;
		return result;
	}
	_tmp17_ = self->priv->casual_parser;
	_tmp18_ = chrono_en_casual_date_parser_parse (_tmp17_, text);
	_g_object_unref0 (_result_);
	_result_ = _tmp18_;
	_tmp19_ = _result_;
	if (_tmp19_ != NULL) {
		result = _result_;
		return result;
	}
	_tmp20_ = self->priv->casual_time_parser;
	_tmp21_ = chrono_en_casual_time_parser_parse (_tmp20_, text);
	_g_object_unref0 (_result_);
	_result_ = _tmp21_;
	_tmp22_ = _result_;
	if (_tmp22_ != NULL) {
		result = _result_;
		return result;
	}
	_tmp23_ = self->priv->month_parser;
	_tmp24_ = chrono_en_month_name_parser_parse (_tmp23_, text);
	_g_object_unref0 (_result_);
	_result_ = _tmp24_;
	_tmp25_ = _result_;
	if (_tmp25_ != NULL) {
		result = _result_;
		return result;
	}
	_tmp26_ = self->priv->relative_parser;
	_tmp27_ = chrono_en_relative_date_format_parser_parse (_tmp26_, text);
	_g_object_unref0 (_result_);
	_result_ = _tmp27_;
	_tmp28_ = _result_;
	if (_tmp28_ != NULL) {
		result = _result_;
		return result;
	}
	_tmp29_ = self->priv->time_expr_parser;
	_tmp30_ = chrono_en_time_expression_parser_parse (_tmp29_, text);
	_g_object_unref0 (_result_);
	_result_ = _tmp30_;
	_tmp31_ = _result_;
	if (_tmp31_ != NULL) {
		result = _result_;
		return result;
	}
	result = NULL;
	_g_object_unref0 (_result_);
	return result;
}

static void
chrono_english_parser_class_init (ChronoEnglishParserClass * klass,
                                  gpointer klass_data)
{
	chrono_english_parser_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ChronoEnglishParser_private_offset);
	((ChronoLanguageParserClass *) klass)->parse = (ChronoParseResult* (*) (ChronoLanguageParser*, const gchar*, gboolean)) chrono_english_parser_real_parse;
	G_OBJECT_CLASS (klass)->finalize = chrono_english_parser_finalize;
}

static void
chrono_english_parser_instance_init (ChronoEnglishParser * self,
                                     gpointer klass)
{
	self->priv = chrono_english_parser_get_instance_private (self);
}

static void
chrono_english_parser_finalize (GObject * obj)
{
	ChronoEnglishParser * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CHRONO_TYPE_ENGLISH_PARSER, ChronoEnglishParser);
	_g_object_unref0 (self->priv->recurrence_parser);
	_g_object_unref0 (self->priv->combo_parser);
	_g_object_unref0 (self->priv->iso_parser);
	_g_object_unref0 (self->priv->slash_parser);
	_g_object_unref0 (self->priv->time_parser);
	_g_object_unref0 (self->priv->casual_parser);
	_g_object_unref0 (self->priv->casual_time_parser);
	_g_object_unref0 (self->priv->month_parser);
	_g_object_unref0 (self->priv->relative_parser);
	_g_object_unref0 (self->priv->time_expr_parser);
	G_OBJECT_CLASS (chrono_english_parser_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
chrono_english_parser_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ChronoEnglishParserClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) chrono_english_parser_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ChronoEnglishParser), 0, (GInstanceInitFunc) chrono_english_parser_instance_init, NULL };
	GType chrono_english_parser_type_id;
	chrono_english_parser_type_id = g_type_register_static (CHRONO_TYPE_LANGUAGE_PARSER, "ChronoEnglishParser", &g_define_type_info, 0);
	ChronoEnglishParser_private_offset = g_type_add_instance_private (chrono_english_parser_type_id, sizeof (ChronoEnglishParserPrivate));
	return chrono_english_parser_type_id;
}

GType
chrono_english_parser_get_type (void)
{
	static gsize chrono_english_parser_type_id__once = 0;
	if (g_once_init_enter (&chrono_english_parser_type_id__once)) {
		GType chrono_english_parser_type_id;
		chrono_english_parser_type_id = chrono_english_parser_get_type_once ();
		g_once_init_leave (&chrono_english_parser_type_id__once, chrono_english_parser_type_id);
	}
	return chrono_english_parser_type_id__once;
}

